Commit graph

171 commits

Author SHA1 Message Date
David Pedersen
b315b60bca
Bump version of all crates (#1310)
* Bump version of all crates

* use the right versions inside the workspace
2022-08-23 22:57:13 +02:00
David Pedersen
fa51cf5266
Support turning any Service into a MakeService (#1302)
* Add `ServiceExt`

* changelog
2022-08-22 22:03:48 +02:00
David Pedersen
ab36e65449
Add RequestExt and RequestPartsExt (#1301)
* Add `RequestExt` and `RequestPartsExt`

* don't double box futures

* changelog pr link
2022-08-22 18:34:46 +02:00
David Pedersen
be624306f4
Only allow last extractor to mutate the request (#1272)
* Only allow last extractor to mutate the request

* Change `FromRequest` and add `FromRequestParts` trait (#1275)

* Add `Once`/`Mut` type parameter for `FromRequest` and `RequestParts`

* 🪄

* split traits

* `FromRequest` for tuples

* Remove `BodyAlreadyExtracted`

* don't need fully qualified path

* don't export `Once` and `Mut`

* remove temp tests

* depend on axum again

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* Port `Handler` and most extractors (#1277)

* Port `Handler` and most extractors

* Put `M` inside `Handler` impls, not trait itself

* comment out tuples for now

* fix lints

* Reorder arguments to `Handler` (#1281)

I think `Request<B>, Arc<S>` is better since its consistent with
`FromRequest` and `FromRequestParts`.

* Port most things in axum-extra (#1282)

* Port `#[derive(TypedPath)]` and `#[debug_handler]` (#1283)

* port #[derive(TypedPath)]

* wip: #[debug_handler]

* fix #[debug_handler]

* don't need itertools

* also require `Send`

* update expected error

* support fully qualified `self`

* Implement FromRequest[Parts] for tuples (#1286)

* Port docs for axum and axum-core (#1285)

* Port axum-extra (#1287)

* Port axum-extra

* Update axum-core/Cargo.toml

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* remove `impl FromRequest for Either*`

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* New FromRequest[Parts] trait cleanup (#1288)

* Make private module truly private again

* Simplify tuple FromRequest implementation

* Port `#[derive(FromRequest)]` (#1289)

* fix tests

* fix docs

* revert examples

* fix docs link

* fix intra docs links

* Port examples (#1291)

* Document wrapping other extractors (#1292)

* axum-extra doesn't need to depend on axum-core (#1294)

Missed this in https://github.com/tokio-rs/axum/pull/1287

* Add `FromRequest` changes to changelogs (#1293)

* Update changelog

* Remove default type for `S` in `Handler`

* Clarify which types have default types for `S`

* Apply suggestions from code review

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* remove unused import

* Rename `Mut` and `Once` (#1296)

* fix trybuild expected output

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-08-22 12:23:20 +02:00
David Pedersen
f1769e5134
Re-organize changelog to make updating to 0.6 easier (#1274) 2022-08-20 21:11:02 +02:00
David Pedersen
423308de3c
Add type safe state extractor (#1155)
* begin threading the state through

* Pass state to extractors

* make state extractor work

* make sure nesting with different states work

* impl Service for MethodRouter<()>

* Fix some of axum-macro's tests

* Implement more traits for `State`

* Update examples to use `State`

* consistent naming of request body param

* swap type params

* Default the state param to ()

* fix docs references

* Docs and handler state refactoring

* docs clean ups

* more consistent naming

* when does MethodRouter implement Service?

* add missing docs

* use `Router`'s default state type param

* changelog

* don't use default type param for FromRequest and RequestParts

probably safer for library authors so you don't accidentally forget

* fix examples

* minor docs tweaks

* clarify how to convert handlers into services

* group methods in one impl block

* make sure merged `MethodRouter`s can access state

* fix docs link

* test merge with same state type

* Document how to access state from middleware

* Port cookie extractors to use state to extract keys (#1250)

* Updates ECOSYSTEM with a new sample project (#1252)

* Avoid unhelpful compiler suggestion (#1251)

* fix docs typo

* document how library authors should access state

* Add `RequestParts::with_state`

* fix example

* apply suggestions from review

* add relevant changes to axum-extra and axum-core changelogs

* Add `route_service_with_tsr`

* fix trybuild expectations

* make sure `SpaRouter` works with routers that have state

* Change order of type params on FromRequest and RequestParts

* reverse order of `RequestParts::with_state` args to match type params

* Add `FromRef` trait (#1268)

* Add `FromRef` trait

* Remove unnecessary type params

* format

* fix docs link

* format examples

* Avoid unnecessary `MethodRouter`

* apply suggestions from review

Co-authored-by: Dani Pardo <dani.pardo@inmensys.com>
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-08-17 15:13:31 +00:00
David Pedersen
6cd356690d
Annotate panicking functions with #[track_caller] (#1248) 2022-08-11 12:45:42 +02:00
David Pedersen
50a4be999d
Update matchit and fix nesting inconsistencies (#1086)
* Break `Router::nest` into `nest` and `nest_service` methods

* fix doc tests

* update docs

* fix

* Only accept `Router` in `Resource::{nest, nest_collection}`

* update changelog

* fix docs

* fix `MatchedPath` with `Router`s nested with `nest_service`

* Apply suggestions from code review

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* adjust docs for fallbacks

* Always nest services as opaque

* fix old docs reference

* more tests for `MatchedPath` with nested handlers

* minor clean up

* use identifier captures in format strings

* Apply suggestions from code review

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* fix test

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-08-11 10:17:08 +00:00
Jonas Platte
7cbb7cf135
Use new Cargo features to avoid implicit features for optional dependencies (#1239)
* Fix changelog entry for MSRV change in axum-extra 0.3.5

* Bump MSRV to 1.60 for axum, axum-extra, axum-macros

* Use new Cargo features to avoid implicit features for optional dependencies
2022-08-09 18:43:02 +02:00
David Pedersen
b243e171fd
Accept S::Response: IntoResponse everywhere (#1165) 2022-07-19 18:55:15 +02:00
SzudemJ
73041c8988
Avoid exposure of type names by QueryRejection (#1171) 2022-07-18 13:43:18 +00:00
David Pedersen
329bd5f9b4
Support any middleware response that implements IntoResponse (#1152)
* Support any middleware response that implements `IntoResponse`

* Require `Infallible` for middleware added with `Handler::layer`
2022-07-13 08:38:19 +00:00
David Pedersen
92dbbd3182
Return rejection if WebSocket request couldn't be upgraded (#1135)
* Return rejection if `WebSocket` request couldn't be upgraded

* make rejection about connection upgrades

* changelog links
2022-07-11 14:33:55 +02:00
David Pedersen
2966407dc1
Re-export debug_handler from axum (#1144)
* Re-export `debug_handler` from axum

Fixes #1143

* also axum-extra
2022-07-04 09:10:52 +00:00
David Pedersen
2e80ebd18d Support running extractors from middleware::from_fn 2022-07-03 16:49:20 +02:00
NicolaLS
34146f3139
Implement TryFrom<Method> for MethodFilter (#1130)
* implement TryFrom<http::Method> for MethodFilter

* test for TryFrom<http::Method> for MethodFilter

* 'UnsupportedMethod' error type for MethodFilter

* Log TryFrom<http::Method> for MethodFilter

* adjust docs

* move docs

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-07-01 08:37:41 +00:00
David Pedersen
a4c820420d
Remove trailing slash redirects (#1119)
* Prepare axum-next branch

* Remove deprecated `extractor_middleware` function (#1077)

* Allow `Error: Into<Infallible>` for `Route::{layer, route_layer}` (#948)

* 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

* fixup changelog

* Panic on overlapping routes in `MethodRouter` (#1102)

* Panic on overlapping routes in `MethodRouter`

* changelog link

* add test to ensure `head` and `get` don't overlap

* Fix changelog

* Prepare axum-next branch

* Remove trailing slash redirects

* changelog link

* Fix changelog

* remove asserting to make make the test more clear

* remove tsr related feature

* Add `RouterExt::route_with_tsr`

* Apply suggestions from code review

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* Update axum-extra/src/routing/mod.rs

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* fix typos in docs

* Update axum/CHANGELOG.md

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* mention `RouterExt::route_with_tsr` in the changelog

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-06-30 00:22:43 +02:00
David Pedersen
23808f72a2 Fix changelog 2022-06-28 22:07:10 +02:00
David Pedersen
2b386c0baa Panic on overlapping routes in MethodRouter (#1102)
* Panic on overlapping routes in `MethodRouter`

* changelog link

* add test to ensure `head` and `get` don't overlap
2022-06-28 22:07:10 +02:00
David Pedersen
661473dcbc Allow Error: Into<Infallible> for Route::{layer, route_layer} (#948)
* 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

* fixup changelog
2022-06-28 22:07:10 +02:00
David Pedersen
56ddabcd7d Remove deprecated extractor_middleware function (#1077) 2022-06-28 22:07:10 +02:00
David Pedersen
7e794e9d1d
axum: Version 0.5.10 (#1128) 2022-06-28 21:32:39 +02:00
David Pedersen
a8d0ce8c03
Fix possible panic when doing trailing slash redirect (#1124)
* Fix possible panic when doing trailing slash redirect

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

* changelog link

* Update axum/src/routing/mod.rs

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-06-28 16:58:13 +02:00
David Pedersen
cb207472f4
Make Router faster to clone (#1123)
* Make `Router` faster to clone

* changelog

* Update axum/src/routing/mod.rs

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* fix

* Update axum/src/routing/mod.rs

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-06-27 11:00:19 +02:00
David Pedersen
fabb205a9e
axum: Version 0.5.9 (#1108) 2022-06-20 13:44:15 +02:00
David Pedersen
7f203b96e6
Fix build with form feature without headers feature (#1107)
Fixes #1106
2022-06-20 09:14:21 +02:00
David Pedersen
5ac0b2b3d7
axum: Version 0.5.8 (#1104) 2022-06-18 11:38:52 +02:00
David Pedersen
2f64064650
Implement IntoResponse for Form (#1095) 2022-06-17 18:23:57 +00:00
David Pedersen
93251fa203
Bump MSRV to 1.56 and update to the 2021 edition (#1098) 2022-06-17 20:11:35 +02:00
David Pedersen
dbdbd0165e
Support Forwarded in Host extractor (#1078)
* Support `Forwarded` in `Host` extractor

* changelog

* Update axum/src/extract/host.rs

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* look for `host` key

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-06-10 22:30:01 +02:00
David Pedersen
7aa3f35129
axum: Version 0.5.7 (#1075) 2022-06-08 16:08:11 +02:00
David Pedersen
0936a246bf
Add extract::ws::close_code which contains constants for close codes (#1067)
The values and docs are copied from [tungstenite].

Fixes #1061

[tungstenite]: https://docs.rs/tungstenite/0.17.2/src/tungstenite/protocol/frame/coding.rs.html#119-188
2022-06-08 09:36:59 +02:00
David Pedersen
8ff275499b Add #1049 to changelogs 2022-06-06 18:00:52 +02:00
David Pedersen
6c10f41d94
Support Path<Vec<(String, String)>> (#1059)
* Support `Path<Vec<(String, String)>>`

* changelog
2022-05-27 14:11:33 +02:00
Christofer Nolander
d7c4e2f807
Implement Default for Extension (#1043) 2022-05-18 15:44:08 +00:00
David Pedersen
316e20fbd9
axum: Version 0.5.6 (#1033) 2022-05-15 23:05:00 +02:00
David Pedersen
178e1801e9
Add axum_extra::extract::Form (#1031)
* Add `axum_extra::extra::Form`

* update tokio-util ban
2022-05-15 15:17:45 +00:00
David Pedersen
08cbade3cb
Improve Path error when its extracted multiple times (#1023)
* Improve `Path` error

* Improve docs

* changelog

* Update axum/src/extract/path/mod.rs

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* fix test

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-05-11 11:38:37 +02:00
Matteo Joliveau
280334347b
Add protocol field to WebSocket (#1022)
* Add protocol field to WebSocket

Signed-off-by: Matteo Joliveau <matteojoliveau@gmail.com>

* Use HeaderValue instead of String

Signed-off-by: Matteo Joliveau <matteojoliveau@gmail.com>

* Update axum/src/extract/ws.rs

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

* Update changelog

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-05-11 08:49:44 +00:00
David Pedersen
96aaac4865
axum: Version 0.5.5 (#1014) 2022-05-10 11:43:08 +00:00
David Pedersen
a3a32f493e
Add MethodRouter::{into_make_service, into_make_service_with_connect_info} (#1010) 2022-05-08 19:48:48 +02:00
David Pedersen
d19beffd6d
Handle GET, HEAD, and OPTIONS correctly in ContentLengthLimit (#989)
* Handle `GET`/`HEAD`/`OPTIONS` in `ContentLengthLimit`

* changelog

* Apply suggestions from code review

Co-authored-by: Marcus Griep <marcus@griep.us>

* Don't allow GET/HEAD/OPTIONS with `transfer-encoding: chunked`

* simplify constructing chunked body

* Update axum/src/extract/content_length_limit.rs

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

Co-authored-by: Marcus Griep <marcus@griep.us>
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-05-05 09:17:54 +02:00
David Pedersen
a723ed1453
axum: Version 0.5.4 (#973) 2022-04-26 16:50:44 +02:00
David Pedersen
79f6cde3b1
Update to tower-http 0.3.0 (#965)
* Update to tower-http 0.3.0

* changelog link
2022-04-25 14:59:16 +00:00
Arniu Tseng
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 <david.pdrsn@gmail.com>
2022-04-24 15:31:17 +00:00
Nathaniel McCallum
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 <nathaniel@profian.com>

* 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 <jplatte+git@posteo.de>

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-04-21 16:24:29 +02:00
David Pedersen
061e66c236
axum: Version 0.5.3 (#947)
* axum: Version 0.5.3

* Update axum/CHANGELOG.md

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-04-19 17:00:51 +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
883a1cfd8f axum: Version 0.5.2 2022-04-19 16:19:43 +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 Calavera
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 <david.calavera@gmail.com>

* 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 <david.calavera@gmail.com>

* Remove extra assignment.

Signed-off-by: David Calavera <david.calavera@gmail.com>

* Update axum/src/routing/mod.rs

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>

* changelog

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-04-17 21:12:52 +00:00
Grachev Mikhail
4c936dbb52
Fix a typo in CHANGELOG.md (#906) 2022-04-04 09:26:39 +02:00
Tristan Bouchard
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 <david.pdrsn@gmail.com>
2022-04-04 09:26:11 +02:00
David Pedersen
3e716f303f axum: Version 0.5.1 2022-04-03 20:23:18 +02:00
Jonas Platte
1191b58083
Add RequestParts::extract (#897) 2022-04-01 09:25:15 +02:00
David Pedersen
fec64bc1b6 axum: Version 0.5.0 2022-03-31 20:37:45 +02:00
David Pedersen
d7860ea9e2
Copy over changelogs from v0.4.x branch (#893)
* Copy over changelogs from v0.4.x branch

Preparing to release 0.5

* bump crate versions
2022-03-31 20:21:55 +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
Evan Schwartz
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 <david.pdrsn@gmail.com>
2022-03-31 10:03:06 +02: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
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 <jplatte+git@posteo.de>

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-03-18 16:53:39 +01:00
David Pedersen
88974f4299
Add missing changelog items (#845)
* Add missing changelog items

* Update axum/CHANGELOG.md

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-03-09 15:07:41 +00:00
David Pedersen
14960e9a11 fix changelog links 2022-03-09 15:43:54 +01: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
Trent
843437b501
Add Host extractor (#827) 2022-03-06 16:29:10 +00: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
Jonas Platte
ab486198e6
Fix typo in CHANGELOG.md (#822) 2022-03-04 00:18:37 +01: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
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
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 Pedersen
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 <jplatte@users.noreply.github.com>

* changelog

Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
2022-02-28 23:04:33 +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
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
c135436cc9
Fix setting content-length: 0 for HEAD responses with compression middleware (#755)
* Fix getting `content-length` for `chunked` responses

Fixes #747

* changelog

* Fix `cargo deny bans`

https://github.com/tokio-rs/axum/pull/753 will fix things properly
2022-02-14 09:56:08 +00:00
David Pedersen
515495d957
Set content-length for responses to HEAD requests (#734)
* Set `content-length` internally in `Router`

* changelog

* require `B: HttpBody` at the `impl`

* add changelog refs
2022-01-31 13:48:51 +01:00
David Pedersen
513766b9e7
Set Allow header when returning 405 Method Not Allowed (#733) 2022-01-30 21:41:34 +01:00
Alex
b1283e9708
Fix year for the 0.4.4 release (#727) 2022-01-26 08:17:39 +01:00
David Pedersen
9004a14302
Move middleware::from_fn into axum (#719)
* Move `middleware::from_fn` into axum

* changelog

* fix feature

* Rephrase changelog a bit
2022-01-25 10:19:06 +01:00
David Pedersen
4f6e86f026 Fixup changelogs 2022-01-25 09:46:26 +01:00
Jonas Platte
bf83f34617 Add trait IntoResponseHeaders (#649)
* Introduce IntoResponseHeaders trait

* Implement IntoResponseHeaders for HeaderMap

* Add impl IntoResponse for impl IntoResponseHeaders

… and update IntoResponse impls that use HeaderMap to be generic instead.

* Add impl IntoResponseHeaders for Headers

… and remove IntoResponse impls that use it.

* axum-debug: Fix grammar in docs

* Explain confusing error message in docs
2022-01-23 18:01:52 +01:00
David Pedersen
b1ef0be1a7 Remove RequestParts::take_extensions (#699)
* Remove `RequestParts::take_extensions`

* fix out of date docs

* Remove RequestAlreadyExtracted and replace it with BodyAlreadyExtracted

* fix docs

* fix test

* Update axum-core/src/extract/mod.rs

Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>

* Remove macro only used once

Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
2022-01-23 18:01:52 +01:00
David Pedersen
184ea656c0 Change HeaderMap extractor to clone the headers (#698)
* Change `HeaderMap` extractor to clone the headers

* fix docs

* changelog

* inline variable

* also add changelog item to axum

* don't list types from axum in axum-core's changelog

* document that `HeaderMap::from_request` clones the headers

* fix typo

* a few more typos
2022-01-23 18:01:52 +01:00
Sabrina Jewson
d5694f0d0d Make sse::Event build event as a BytesMut (#647)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-01-23 18:01:52 +01:00
David Pedersen
d97f2aeae6 Make TypedHeaderRejectionReason #[non_exhaustive] (#665)
* Make `TypedHeaderRejectionReason` `#[non_exhaustive]`

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

* add changelog pr link
2022-01-23 18:01:52 +01:00
David Pedersen
5d79c638f4 Require Output = () on WebSocketStream::on_upgrade (#646)
Fixes https://github.com/tokio-rs/axum/issues/636
2022-01-23 18:01:52 +01:00
David Pedersen
5fe981a1da
axum: Version 0.4.4 (#706)
- **fixed:** Fix using incorrect path prefix when nesting `Router`s at `/` ([#691])
- **fixed:** Make `nest("", service)` work and mean the same as `nest("/", service)` ([#691])
- **fixed:** Replace response code `301` with `308` for trailing slash redirects. Also deprecates
  `Redirect::found` (`302`) in favor of `Redirect::temporary` (`307`) or `Redirect::to` (`303`).
  This is to prevent clients from changing non-`GET` requests to `GET` requests ([#682])

[#691]: https://github.com/tokio-rs/axum/pull/691
[#682]: https://github.com/tokio-rs/axum/pull/682
2022-01-13 10:37:33 +01:00
Nick Ashley
007a0e85f2
Use 308 instead of 301 for trailing slash redirects (#682)
* Use 308 status instead of 301 when redirecting

For redirects resulting from requests to paths with a trailing slash,
use 308 instead of 301 to prevent non-GET requests (POST, PUT, etc) from
being changed to GET.

For example, (assuming a route for /path is defined)...
  - Old behavior results in:
  POST /path/ -> GET /path

  - New behavior results in:
  POST /path/ -> POST /path

Fixes #681

* Add deprecation notice to found()

Deprecates found() due to its use of HTTP 302

* rustfmt

* Use dedicated redirect method

Use Redirect::permanent instead of re-implementing its functionality

* Remove deprecated method from example

Replace usages of Redirect:found with Redirect::to and Redirect::temporary as appropriate

* Fix panic in oauth example

Previously the example would panic if a request was made without the
`Cookie` header. Now the user is redirected to the login page as
expected.

* Update CHANGELOG

* Revert pub TypedheaderRejection fields

* Fix clippy lint

* cargo fmt

* Fix CHANGELOG link

* Adhere to implicit line length limit
2022-01-12 15:14:06 +01:00
David Pedersen
d181867355
Fix nesting Router at / leading to double slash in the path (#691)
* Fix nesting router at `/`

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

* Allow nesting at `""`

* changelog

* remove outdated test
2022-01-06 12:12:24 +01:00
David Pedersen
4c48efc861
axum: Version 0.4.3 (#650) 2021-12-21 15:41:03 +01:00
David Pedersen
c50b55384c
Add ExtensionsAlreadyExtracted to PathRejection (#619)
* Add `ExtensionsAlreadyExtracted` to `PathRejection`

* format imports

* changelog
2021-12-12 23:51:18 +01:00
Kai Jewson
d9bf100216
Don't drop leading spaces in SSE responses (#600)
* Don't drop leading spaces in SSE responses

* Mention leading space fix in changelog

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2021-12-12 16:11:15 +00:00
Kai Jewson
6feea82d61
Enforce stronger validation of SSE values (#599)
* Enforce stronger validation of SSE values

* Mention `sse::Event` strictness in changelog

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2021-12-12 16:03:20 +00:00
Jonas Platte
b1623ce7f2
Add AddExtension::layer (#607) 2021-12-10 22:56:56 +01:00
David Pedersen
4b85b227e1 Update changelog with v0.3.4
This was shipped from the `v0.3.x` branch so wasn't moved to `main`.
2021-12-08 18:38:14 +01:00
David Pedersen
9f6be24ecd
axum: Version 0.4.2 (#592)
* axum: Version 0.4.2

This time depending on the correct version of axum-core.

* add missing changelog links
2021-12-06 12:03:13 +00:00
David Pedersen
8e1341d1f6
Release axum, axum-core, and axum-debug (#591) 2021-12-06 10:30:09 +01:00