Commit Graph
236 Commits
Author SHA1 Message Date
David Pedersen 23f20ea1f3 Replace ByteStr with Arc<str> (#971) 2022-04-26 10:16:38 +02:00
takumi bc6fefb052 Remove needless map (#970) 2022-04-26 09:15:04 +02:00
Arniu TsengandDavid Pedersen ebecac57a3 Add FromExtractor and deprecate extractor_middleware (#957)
* Add from_extractor and deprecate extractor_middleware

* Fix clippy warnings

* Update CHANGELOG.md

* Clean doc

* Add ExtractorMiddleware* back for compatibility

* Revert "Update CHANGELOG.md"

* remove dedundant docs

* allow re-exporting deprecated types

Co-authored-by: David Pedersen <[email protected]>
2022-04-24 15:31:17 +00:00
takumi 98795b7f75 Replace to_string with to_owned (#960) 2022-04-24 08:05:00 +00:00
takumi 0d2c61c472 Remove needless borrow (#961) 2022-04-24 08:03:54 +00:00
8084b242d5 Add response::ErrorResponse and response::Result (#921)
* feat: add response::{Error, Result}

This type makes for efficient use of the `?` operator when in a function
with multiple return error types that all implement `IntoResponse`.

Signed-off-by: Nathaniel McCallum <[email protected]>

* misc adjustments from PR review

* Rename to `ErrorResponse` and `ResultResponse`

* nitpicky docs changes

* update changelog

* changelog wording

* Apply suggestions from code review

Co-authored-by: Jonas Platte <[email protected]>

Co-authored-by: David Pedersen <[email protected]>
Co-authored-by: Jonas Platte <[email protected]>
2022-04-21 16:24:29 +02:00
David Pedersen 2adb34c8aa Revert "Allow Error: Into<Infallible> for Route::{layer, route_layer} (#924)" (#946)
This reverts commit ca7ecb159b.
2022-04-19 16:47:27 +02:00
David Pedersen ca7ecb159b Allow Error: Into<Infallible> for Route::{layer, route_layer} (#924)
* Allow `Error: Into<Infallible>` for `Route::{layer, route_layer}`

Fixes https://github.com/tokio-rs/axum/issues/922

* changelog
2022-04-19 16:16:54 +02:00
David Pedersen afcefb4a70 Add AppendHeaders (#927)
* Add `AppendHeaders`

* axum changelog
2022-04-17 23:14:04 +02:00
David CalaveraandDavid Pedersen 83e1a15040 Fix trailing redirection with query parameters (#936)
* Fix trailing redirection with query parameters

When the request URI matches a route that need a trailing slash, or has an extra trailing slash, the redirect URI is not generated correctly.

This change adds or removes a trailing slash to the path part of the URI, instead of the full URI, preserving query parameters during redirection.

Signed-off-by: David Calavera <[email protected]>

* Make trailing slash logic safer

Extract parts from Uri and recreate it, so it doesn't bump
into corner cases with string manipulation.

Signed-off-by: David Calavera <[email protected]>

* Remove extra assignment.

Signed-off-by: David Calavera <[email protected]>

* Update axum/src/routing/mod.rs

Co-authored-by: David Pedersen <[email protected]>

* changelog

Co-authored-by: David Pedersen <[email protected]>
2022-04-17 21:12:52 +00:00
zys864andzys864 d177a65f24 remove path::de "'any'" unneeded single quotes (#926)
* fix `route` module clippy warning

* remove `path::de` `"'any'"` unneeded singgle quotes,changes to `"any"`

Co-authored-by: zys864 <[email protected]>
2022-04-09 18:33:44 +02:00
zys864andzys864 f13eab893a fix route module clippy warnings (#920)
Co-authored-by: zys864 <[email protected]>
2022-04-08 14:28:11 +02:00
Tristan BouchardandDavid Pedersen d417910a16 Add Field::chunk (#901)
* Added chunk function to multipart field

This fixes not being able to stream data from a multipart directly into a file or other output.

* doc comment for clarification of usage and &mut self

* fixed formatting

* Corrected example to reflex best practices

* Removed unwrap

* clean up docs

* update changelog

Co-authored-by: David Pedersen <[email protected]>
2022-04-04 09:26:11 +02:00
David Pedersen 405e3f8c44 Add SpaRouter (#904) 2022-04-03 18:29:37 +02:00
David Pedersen 21552fe434 Remove bound from into_make_service_with_connect_info (#892)
Fixes #859
2022-03-31 16:49:49 +00:00
Yotam Ofek 2e5d56a9b1 Update outdated Query extractor docs. (#891) 2022-03-31 15:43:54 +02:00
Evan SchwartzandDavid Pedersen 3084dc10ca Accept &str for Redirect (#889)
* Accept &str for Redirect

* Fix doc example

* fix more docs examples

* update changelog

* fix changelog label

Co-authored-by: David Pedersen <[email protected]>
2022-03-31 10:03:06 +02:00
Tv dee4e73af4 Typos in docstrings (#886) 2022-03-24 20:56:05 +01:00
David Pedersen 56e2d57320 Change Handler to have an associated Future type (#879)
* Change `Handler` to have an associated `Future` type

This removes `#[async_trait]` from `Handler` and replaces that with an
associated `Future` type.

As hinted at in #878 I'm working on something with types that need to
implement `Handler`. I'm doing that by wrapping other `Handler` types so
I can implement `Handler` by simply delegating and thus don't need to
allocate another box for `#[async_trait]`. This change makes that
possible.

It does make `Handler` less ergonomic to implement but thats a very
niche feature so I'm fine with that. It wouldn't be appropriate for
`FromRequest` IMO.

* changelog
2022-03-21 13:32:06 +00:00
David Pedersen 6175f95f41 Unseal handler trait (#878) 2022-03-21 11:55:31 +01:00
David Pedersen 2c985246ba Fix out of date docs for Json (#871)
Fixes https://github.com/tokio-rs/axum/issues/865
2022-03-19 01:24:28 +01:00
David PedersenandJonas Platte 437fe5b931 Make status codes for JsonRejection more precise (#868)
* Fix status codes for `JsonRejection` rejections

Fixes #865

* Apply suggestions from code review

Co-authored-by: Jonas Platte <[email protected]>

Co-authored-by: Jonas Platte <[email protected]>
2022-03-18 16:53:39 +01:00
Nathaniel McCallum 30b2cf8f96 Implement From<S> for StreamBody<S> (#866)
Although this shadows `StreamBody::new()`, having `From` allows for
trivial bounds creation on associated types.

Signed-off-by: Nathaniel McCallum <[email protected]>
2022-03-18 15:40:27 +00:00
David Pedersen 401c7a324a Fix routing for opaque nested services (#842)
* Fix routing for opaque nested services

* Also test `MatchedPath`

* clean up and more comments
2022-03-09 11:25:06 +01:00
David Pedersen 70e3024068 Don't set extension we never use (#844)
* Remove unused internal helper

* Don't set extension we never use
2022-03-09 11:05:24 +01:00
David Pedersen f9a94ca7eb Add security note about extract::Host (#839) 2022-03-09 10:18:12 +01:00
Ibraheem Ahmed 04dd7617a4 update to matchit 0.5 (#843) 2022-03-09 09:28:19 +01:00
David Pedersen dfa2e3b09f Fix nesting of opaque services that paths that contain params (#841)
* checkpoint

* fix it

* more consistent macros

* fix msrv
2022-03-08 21:27:44 +01:00
David Pedersen 0600eff31a Use IntoResponse rather than Response::builder internally (#837) 2022-03-07 16:49:03 +01:00
Trent 843437b501 Add Host extractor (#827) 2022-03-06 16:29:10 +00:00
David Pedersen b05a5c6dfe Make it more obvious that NEST_TAIL_PARAM is reserved (#836) 2022-03-06 16:01:14 +00:00
David Pedersen a438e6b106 Refactor storing URL params in extensions (#833) 2022-03-06 12:41:16 +01:00
David Pedersen 1614ef7a22 Fix inconsistent double slash when nesting routes (#824) 2022-03-04 09:28:44 +01:00
David Pedersen 90e74f12c4 Requires paths start with a / (#823)
* Requires routes to start with `/`

* Also check routes in `TypedPath`

* changelog

* changelog links
2022-03-03 23:24:27 +00:00
David Pedersen d943ba6d81 Replace HasRoutes with Into<Router> (#819)
* Move `HasRoutes` into axum

* fix doc test

* Just use `Into<Router>`
2022-03-03 21:50:31 +00:00
David Pedersen 5f54855b05 Remove IntoResponse and IntoResponseParts impls for Version (#815) 2022-03-02 13:07:16 +00:00
David Pedersen 84c725a1ae Make IntoResponseParts more flexible (#813)
* Make `IntoResponseParts` more flexible

* fix `impl<T> IntoResponseParts for TypedHeader<T>`

* fix
2022-03-02 11:41:14 +00:00
David Pedersen 24359ebd4d Move TypedHeader into root (#803) 2022-03-01 16:00:42 +00:00
David Pedersen 2428d99081 Export AddExtension from middleware (#811)
* Export `AddExtension` from `middleware`

* Move `AddExtension` into `extension` module
2022-03-01 13:59:33 +00:00
David Pedersen 2de202da40 Remove AddExtensionLayer (#807)
* Remove `AddExtensionLayer`

Its deprecated on 0.4.x so we can remove it from `main`.

* changelog
2022-03-01 13:59:43 +01:00
David Pedersen 094fd71d1a Move Extension into root (#804) 2022-03-01 09:12:45 +01:00
David Pedersen a2b568c7c1 Implement tower::Layer for Extension (#801)
* Implement `tower::Layer` for `Extension`

* changelog
2022-03-01 00:39:22 +01:00
David Pedersen 0d05b5e31f Remove deprecated APIs (#800)
* Remove deprecations APIs

* changelog
2022-02-28 23:22:21 +00:00
David PedersenandJonas Platte f12ab072c5 Add IntoResponseParts (#797)
* Add `IntoResponseParts`

* docs

* Add test

* don't allow overriding body or response

* macroify impls

* re-order things a bit

* Fix tests

* Also allow overriding version

* Move things into separate modules

* docs

* clean up

* fix trybuild test

* remove churn

* simplify buliding response

* fixup test

* fix docs typo

* Use `HeaderValue::from_static`, might be faster

* Bring back `impl IntoResponse` in example

* Remove blanket impl to improve error message

* don't need to set `content-type`

* Apply suggestions from code review

Co-authored-by: Jonas Platte <[email protected]>

* changelog

Co-authored-by: Jonas Platte <[email protected]>
2022-02-28 23:04:33 +00:00
David Pedersen 8175b9108f Improve error for missing extension (#795) 2022-02-25 19:42:36 +01:00
Spyros Roum e2dc6b3147 Remove outdated documentation (#793)
Fixes: #792
2022-02-25 14:35:43 +00:00
David Pedersen 4ccc4bea71 Update to tokio-tungstenite 0.17 (#791)
Fixes https://github.com/tokio-rs/axum/issues/781
2022-02-25 10:42:09 +00:00
David Pedersen e781b7b936 Fix some out of date docs (#784)
Since https://github.com/tokio-rs/axum/pull/698 this section about
`HeaderMap` removing the headers from the request is no longer true.
2022-02-24 16:22:52 +01:00
David Pedersen 113a15a713 Document sharing state between handler and middleware (#783)
* Fix heading levels

* Document passing state from middleware to handlers
2022-02-22 16:14:18 +01:00
David Pedersen 49d8fc5093 Make middleware::from_fn response future public (#778)
* Make `middleware::from_fn` response future public

* Make module name consistent with tower
2022-02-22 13:30:47 +01:00