They'd previously see the nested URI as we mutated the request. Now we
always route based on the nested URI (if present) without mutating the
request. Also meant we could get rid of `OriginalUri` which is nice.
Previously, on `main`, this wouldn't compile:
```rust
let app = route("/", get(handler))
.layer(
ServiceBuilder::new()
.timeout(Duration::from_secs(10))
.into_inner(),
)
.handle_error(...)
.route(...); // <-- doesn't work
```
That is because `handle_error` would be
`axum::service::ServiceExt::handle_error` which returns `HandleError<_,
_, _, HandleErrorFromService>` which does _not_ implement `RoutingDsl`.
So you couldn't call `route`. This was caused by
https://github.com/tokio-rs/axum/pull/120.
Basically `handle_error` when called on a `RoutingDsl`, the resulting
service should also implement `RoutingDsl`, but if called on another
random service it should _not_ implement `RoutingDsl`.
I don't think thats possible by having `handle_error` on `ServiceExt`
which is implemented for any service, since all axum routers are also
services by design.
This resolves the issue by removing `ServiceExt` and moving its methods
to `RoutingDsl`. Then we have more tight control over what has a
`handle_error` method.
`service::OnMethod` now also has a `handle_error` so you can still
handle errors from random services, by doing
`service::any(svc).handle_error(...)`.
* feat(ws): make Message an enum to allow pattern matching
* fix(examples): update to new websockets `Message`
* fix(ws): remove wildcard imports
* fix(examples/chat): apply clippy's never_loop
* style: `cargo fmt`
* docs:add license notes above parts that are copied
* fix(ws): make CloseCode an alias to u16
* fix: move Message from src/ws/mod.rs to src/extract/ws.rs
* docs: add changelog entry about websocket messages
* fix: remove useless convertions to the same type
Adds associated `Body` and `BodyError` types to `IntoResponse`. This is required for returning responses with bodies other than `hyper::Body` from handlers. That wasn't previously possible.
This is a breaking change so should be shipped in 0.2.
With this you'll be able to do:
```rust
let one = route("/foo", get(|| async { "foo" }))
.route("/bar", get(|| async { "bar" }));
let two = route("/baz", get(|| async { "baz" }));
let app = one.or(two);
```
Fixes https://github.com/tokio-rs/axum/issues/101
As described in
https://github.com/tokio-rs/axum/pull/108#issuecomment-892811637, a
`HandleError` created from `axum::ServiceExt::handle_error` should _not_
implement `RoutingDsl` as that leads to confusing routing behavior.
The technique used here of adding another type parameter to
`HandleError` isn't very clean, I think. But the alternative is
duplicating `HandleError` and having two versions, which I think is less
desirable.
These types were moved around in
https://github.com/tokio-rs/axum/pull/130 but re-export from their old
location for backwards compatibility.
This removes the re-exports.
https://github.com/tokio-rs/axum/pull/129 was a breaking change, in part
because I had to remove the `Copy` impl from `OnMethod`.
For the sake of future proofing I think we should remove other `Copy`
impls from services as well. We can always bring them back once things
have matured more.
These types no longer implement `Copy`:
- `EmptyRouter`
- `ExtractorMiddleware`
- `ExtractorMiddlewareLayer`
* Feature-gate test that depends on non-default features
Makes `cargo check` work without extra flags.
* Don't set doc(html_root_url)
It is no longer recommended:
https://github.com/rust-lang/api-guidelines/pull/230
* Remove documentation URL from Cargo.toml
crates.io will link to the right version on docs.rs automatically.
* Ensure toolchains installed by actions-rs/toolchain are actually used
* Fix missing rustup component in check job
* Raise MSRV to 1.51
Older versions weren't actually working before.
* Only run clippy & rustfmt on stable toolchain
MSRV is checked in test-versions.
* Allow cargo doc to succeed without headers and multipart features
CI will still ensure that intra-doc links that rely on these are not broken.