Commit Graph
26 Commits
Author SHA1 Message Date
David Pedersen a128a672a1 Remove allocation when calling handler (#190)
`Handler::call` already returns a boxed future so we don't have to box
it again.
2021-08-16 09:19:37 +02:00
David Pedersen 48afd30491 Improve compile times (#184)
* Inline `handler::IntoService`

* Inline `BoxResponseBody`

* Add missing debug impl
2021-08-15 23:01:26 +02:00
David Pedersen 995ffc1aa2 Correctly handle HEAD requests (#129) 2021-08-15 20:27:13 +02:00
David Pedersen 8013165908 Move methods from ServiceExt to RoutingDsl (#160)
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(...)`.
2021-08-08 14:30:51 +02:00
David Pedersen 72071cf5de Implement MethodFilter via bitflags (#158)
Fixes https://github.com/tokio-rs/axum/issues/107
2021-08-07 23:05:53 +02:00
David Pedersen 6ce355cca3 Add unique future types for all services (#157)
So we can more easily change them in the future.
2021-08-07 22:27:27 +02:00
David Pedersen ab927033b3 Support returning any http_body::Body from IntoResponse (#86)
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.
2021-08-07 18:03:21 +02:00
David Pedersen 95d7582d28 Fix ServiceExt::handle_error footgun (#120)
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.
2021-08-07 16:44:12 +02:00
David Pedersen 123b1b3c5e Remove future re-exports (#133)
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.
2021-08-07 16:22:53 +02:00
David Pedersen 5c12328892 Replace hyper::Server with axum::Server in docs (#118)
* Replace `hyper::Server` with `axum::Server` in docs

* Change readme as well
2021-08-04 15:38:51 +02:00
Jonas Platte 015f6e0c21 Fix typos found by typos-cli (#113) 2021-08-04 12:09:39 +02:00
Sunli be68227d73 Use pin-project-lite instead of pin-project (#95) 2021-08-03 09:33:00 +02:00
David Pedersen 407aa533d7 Return 405 Method Not Allowed for unsupported method for route (#63)
Fixes https://github.com/tokio-rs/axum/issues/61
2021-07-31 21:05:53 +02:00
David Pedersen d843f4378b Make websocket handlers support extractors (#41) 2021-07-30 15:19:53 +02:00
David Pedersen 8faed8120f Docs improvements (#37) 2021-07-22 15:00:33 +02:00
David Pedersen f32d325e55 Make extractors easier to write (#36)
Previously extractors worked directly on `Request<B>` which meant you
had to do weird tricks like `mem::take(req.headers_mut())` to get owned
parts of the request.

This changes that instead to use a new `RequestParts` type that have
methods to "take" each part of the request. Without having to do weird
tricks.

Also removed the need to have `B: Default` for body extractors.
2021-07-22 13:23:50 +02:00
David Pedersen 5a5710d290 Rename to axum (#28) 2021-07-09 21:36:14 +02:00
David Pedersen 3cd4a1d6a6 Fix for service as bottom handler (#27)
Would previously fail because of a mismatch in error types.
2021-07-06 09:40:25 +02:00
David Pedersen c4d266e94d Allow errors (#26)
This changes error model to actually allow errors. I think if we're going to use this for things like tonic's route we need a more flexible error handling model. The same `handle_error` adaptors are still there but services aren't required to have `Infallible` as their error type. The error type is simply propagated all the way through.
2021-07-05 16:18:39 +02:00
David Pedersen 356f1c8424 Generic request body (#22)
Fixes #21
2021-06-19 12:50:33 +02:00
David Pedersen 1002685a20 Rename to awebframework (#13) 2021-06-13 11:22:02 +02:00
David Pedersen 59944c231f Reduce size of response body types (#11)
Wrapping everything in `crate::body::Either` wasn't actually necessary
ans probably causes large body types. You can instead box the bodies in
the leaf services.
2021-06-13 10:10:37 +02:00
David Pedersen 04d62798b6 Reduce body boxing (#9)
Previously, when routing between one or two requests the two body types
would be merged by boxing them. This isn't ideal since it introduces a
layer indirection for each route.

We can't require the services to be routed between as not all services
use the same body type.

This changes that so it instead uses an `Either` enum that implements
`http_body::Body` if each variant does. Will reduce the overall
allocations and hopefully the compiler can optimize things if both
variants are the same.
2021-06-12 23:59:18 +02:00
David Pedersen c91dc7ce29 Make Request<Body> an extractor 2021-06-09 09:42:06 +02:00
David Pedersen 90c3e5ba74 Parameterize ContentLengthLimit 2021-06-09 08:14:20 +02:00
David Pedersen 1f8b39f05d More docs and expand key_value_store example 2021-06-08 12:43:16 +02:00