Commit graph

557 commits

Author SHA1 Message Date
valkyrie_pilot
e4c6d76bca
Implement IntoResponse for [u8; N] and &'static [u8; N] (#1690)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2023-01-13 09:12:51 +00:00
David Pedersen
e3aaeb3cb7
Release axum, axum-core, and axum-macros (#1688) 2023-01-09 13:54:49 +01:00
Austaras
6638b274db
Update to base64 0.20 (#1641) 2023-01-08 15:21:24 +00:00
David Pedersen
be9a8c0380
Document breaking changes related to nest (#1684) 2023-01-07 19:06:59 +01:00
David Pedersen
1aa357c879
Misc documentation improvements (#1647)
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2023-01-07 14:07:54 +01:00
Paolo Barbolini
211de92d24
Enable the runtime feature of hyper when using tokio (#1671) 2023-01-06 12:28:31 +01:00
Tobias Bieniek
2d8242b2c5
docs/middleware: Add missing Clone derive on MyLayer (#1649) 2023-01-05 10:47:38 +00:00
Liigo Zhuang
978ae63358
Update extract.md (#1653) 2022-12-19 08:44:03 +01:00
Jonas Platte
b372244099
Guide people to the right places to ask questions (#1631)
* README: Link to discussions instead of issues in Getting Help section

* Link to Discussions and Discord on new issue page
2022-12-09 10:14:31 +01:00
Mario Kaufmann
e3d8868f99
Minor doc fixes (#1622) 2022-12-06 21:46:35 +00:00
David Pedersen
7e13d69639
Add status and body_text methods to built-in rejections (#1612)
* Add `status` and `body_text` methods to built-in rejections

This should make it easier to customize a built-in rejection while
preserving either the status or body.

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

* changelog
2022-12-02 19:54:16 +01:00
Cemre Mengu
5826ca268c
Add missing import of http in docs example (#1613) 2022-12-02 14:47:04 +00:00
tottoto
56d0dd9ec2
Update to tokio-tungstenite-0.18.0 and use sha1 (#1598) 2022-12-02 11:13:57 +01:00
tottoto
dd4e141f4c
Remove outdated link alias from readme (#1591) 2022-11-29 11:51:44 +01:00
David Pedersen
87a80ec47b
axum v0.6.1 (#1588) 2022-11-29 08:43:18 +00:00
tottoto
3279d64f96
Update to matchit 0.7 (#1582) 2022-11-27 10:19:01 +01:00
LeoniePhiline
28f1996f9c
Clarify nested outer fallbacks in CHANGELOG.md (#1581) 2022-11-27 01:03:13 +01:00
David Pedersen
eb2e933054
Expand the docs for Router::with_state (#1580) 2022-11-27 01:01:59 +01:00
David Pedersen
b984fec572 Remove notice about breaking changes from readme 2022-11-25 22:42:35 +01:00
David Pedersen
1b6780cf6c
axum 0.6 and friends 🎉 (#1570)
* changelog

* bump versions

* reorder changelogs a bit

* Apply suggestions from code review

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

* Expand fallback inheritance

* Reword tsr

* Mention `parse-body-based-on-content-type` example

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-11-25 12:29:58 +00:00
David Pedersen
0b26411f39
Change Router::with_state and impl Service for Router<()> (#1552)
* Implement `Service` for `Router<(), B>`

* wip

* wip

* fix some tests

* fix examples

* fix doc tests

* clean up docs

* changelog

* fix

* also call `with_state` when converting `MethodRouter` into a `MakeService`

* suggestions from review
2022-11-24 14:43:10 +00:00
jimmycuadra
6771729d27
Improve State and Router docs (#1543) 2022-11-22 09:08:39 +01:00
walfie
7d0bb28876
Minor doc fixes (#1562) 2022-11-22 07:08:18 +00:00
Tshepang Mbambo
3ab3e5f91d
Use http re-export in docs (#1554) 2022-11-20 21:48:41 +01:00
David Pedersen
b816ac7cdf
Add RouterService::{layer, route_layer} (#1550)
* Add `RouterService::{layer, route_layer}`

Figure we might as well have these.

* changelog
2022-11-19 21:51:55 +00:00
Jonas Platte
ce8ea56f3b
Small improvements to RouterService (#1548)
* Fix docstrings on RouterService methods

* Simplify signatures of RouterService methods with Self type
2022-11-19 22:26:12 +01:00
Georg Semmler
d5de3bc7e3
Improve compile errors for unimplemented traits (#1436)
* Improve `debug_handler` to use the correct span for specific bounds

This results in better localised error messages, as they now point
directly to the corresponding argument instead of to the macro itself.

* Improve some error messages behind a `nightly-error-messages` feature
flag

This uses the nightly only `rustc_on_unimplemented` attribute to improve
some error messages when users try to use invalid handler functions.
This should be seen as prove of concept, not as full solution for all
potential error cases.

The underlying feature is currently marked as permanently unstable, but
I'm working on getting this specific attribute (or an attribute with
different name, similar functionality) ready to work on a stable compiler.

* Apply suggestions from code review

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

* Enable the `nightly-error-messages` feature unconditionally for nightly compilers

* Use a nightly compiler to run the axum-marcos compile fail tests

* update to newer nightly

* Run axum-macros tests on nightly

* tweak compile error hints a bit

* more tweaks

* update test

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-11-19 12:45:03 +01:00
David Pedersen
2e3000f1a3 Fix typo 2022-11-18 18:36:49 +01:00
David Pedersen
37b9b3df48 Remove duplicate changelog entry 2022-11-18 17:59:05 +01:00
David Pedersen
878ae73e6d
New release candidates (#1541) 2022-11-18 17:29:47 +01:00
David Pedersen
64960bb19c
Type safe state inheritance (#1532)
* Make state type safe

* fix examples

* remove unnecessary `#[track_caller]`s

* Router::into_service -> Router::with_state

* fixup docs

* macro docs

* add missing docs

* fix examples

* format

* changelog

* Update trybuild tests

* Make sure fallbacks are still inherited for opaque services (#1540)

* Document nesting routers with different state

* fix leftover conflicts
2022-11-18 11:02:58 +00:00
David Pedersen
ba8e9c1b21
Add on_failed_upgrade callback to WebSocketUpgrade (#1539)
* Add `on_failed_upgrade` callback to `WebSocket`

Previously if upgrading a connection to a WebSocket connection failed
the background task would panic. There was no way to customize that so
users that might wanna report the error was out of luck.

Panicking also wasn't great because users might abort on panics which
would bring down the server.

* changelog

* Apply suggestions from code review

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

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-11-18 10:53:04 +00:00
David Pedersen
7090649377
Add fallback inheritance for nested routers (#1521)
* fallback inheritance

* cleanup

* changelog
2022-11-18 10:25:04 +00:00
David Pedersen
2e8a7e51a1
Fix Handler::with_state not working if request body was changed via layer (#1536)
Previously

```rust
handler.layer(RequestBodyLimitLayer::new(...)).with_state(...)
```

didn't work because we required the same request body all the way
through.
2022-11-18 11:00:52 +01:00
danielvschoor
c461f1d827
Add accept_unmasked_frames setting in WebSocketUpgrade (#1529)
* Add accept_unmasked_frames setting in WebSocketUpgrade

* Update CHANGELOG.md

* Apply suggestions from code review

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-11-15 09:02:12 +00:00
Taylor Everding
587435940b
Add more tests for the Allow header when returning 405 (#1526)
Refs: #1525, #733
2022-11-14 16:02:05 +01:00
BBaoVanC
370ad07e75
Remove debug_assert in matched_path (#1527) 2022-11-13 02:54:29 +00:00
David Pedersen
74bbe80f8a
axum 0.6.0-rc.4 (#1518) 2022-11-09 13:49:47 +01:00
David Pedersen
028cac4a72
Fix compile error in release mode (#1517) 2022-11-09 13:36:10 +01:00
David Pedersen
1d6a96ee20 Remove references to *_with_state_arc functions from changelog
They were removed again before being released.
2022-11-09 09:27:37 +01:00
David Pedersen
e53c85c496 Minor changelog fixes 2022-11-09 09:20:09 +01:00
David Pedersen
e39d053d2f
New release candidates (#1514)
* New release candidates

* Update axum/Cargo.toml

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

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-11-09 09:01:47 +01:00
David Pedersen
0e3f9d0938
Don't allow extracting MatchedPath in middleware for nested routes (#1462)
* Don't allow extracting `MatchedPath` for nested paths

* misc clean up

* Update docs

* changelog

* Apply suggestions from code review

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

* Add test for nested handler service

* change to `debug_assert`

* apply suggestions from review

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-11-08 20:43:19 +00:00
David Pedersen
e0ef641e5f
Rework Form and Query rejections (#1496)
* Change `FailedToDeserializeQueryString` rejection for `Form`

Its now called `FailedToDeserializeForm`.

* changelog

* Make dedicate rejection type for axum-extra's `Form`

* update trybuild test

* Make dedicate rejection type for axum-extra's `Query`
2022-11-08 20:31:06 +00:00
Jonas Platte
36f24990c8 Fix clippy lints 2022-11-05 11:33:27 +01:00
Jonas Platte
21475f94ff Adjust renamed clippy lint name 2022-11-05 11:33:27 +01:00
David Pedersen
b59c7a8c84
Add example for Router::inherit_state (#1492)
* Add example for `Router::inherit_state`

* clarification

* 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-10-20 19:19:05 +00:00
David Pedersen
4979b4c9b6 Implement Form in terms of RawForm 2022-10-20 20:55:11 +02:00
Marek Kuskowski
bc8a507f58
Add RawForm extractor (#1487)
* Add RawForm extractor

* Change RawForm(String) to RawForm(Option<String>)

* Fix tests

* Use Bytes instead of Option<String> and add tests

* Add test for empty body

* Update CHANGELOG

* small docs tweaks

* changelog nit

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-10-20 18:03:13 +00:00
David Pedersen
9c0a89cd09
Add #[derive(FromRef)] (#1430)
* add `#[derive(FromRef)]`

* tests

* don't support skipping fields

probably wouldn't work at all since the whole state likely needs `Clone`

* UI tests

* changelog

* changelog link

* revert hello-world example, used for testing

* Re-export `#[derive(FromRef)]`

* Don't need to return `Result`

* use `collect` instead of quoting the iterator

* Mention it in axum's changelog
2022-10-10 18:40:14 +00:00
David Pedersen
1681ecf438 Copy changelogs from 0.5.x branch 2022-10-10 20:23:11 +02:00
David Pedersen
d7ba0b1d72
Relax bounds for FromExtractor (#1469)
Fixes #1467

We didn't actually use the bounds. I guess they were left over from a
previous version.
2022-10-10 16:39:16 +00:00
David Pedersen
7420721f4d
Document RouterService (#1465)
Not sure what else there is to say :P

Fixes https://github.com/tokio-rs/axum/issues/1401
2022-10-10 00:23:11 +02:00
David Pedersen
b607ad5823
Improve map_response docs (#1464)
* Document when extractors run

* Document returning `impl IntoResponse`
2022-10-09 23:33:22 +02:00
David Pedersen
f9dc96fdce
Don't internally Arc the state (#1460) 2022-10-09 20:55:28 +00:00
Jonas Platte
a2ab338e68
Rewrite how state is passed from Router to MethodRouter 2022-10-09 19:33:40 +00:00
Jonas Platte
a7d8954178
Use RequestPartsExt more in docs / examples (#1445)
* Use RequestPartsExt more in docs / examples

* Remove unused import
2022-10-04 17:26:51 +00:00
David Pedersen
a57bd9a118 Move changelog item to "unreleased" 2022-10-04 14:25:31 +02:00
Jonas Platte
b94248191e
Add RequestExt::{with_limited_body, into_limited_body} (#1420)
* Move RequestExt and RequestPartsExt into axum-core

* Add RequestExt::into_limited_body

… and use it for Bytes extraction.

* Add RequestExt::with_limited_body

… and use it for Multipart extraction.

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-09-28 20:20:47 +00:00
chuckberrypi
2c833ad276
rmv claim that state can't be passed to middleware (#1426)
axum::middleware::from_fn_with_state now allows middleware to access application state.
2022-09-27 22:19:59 +00:00
Danny
fef95bf37a
Add From impls for extract::ws::Message (#1421)
* Add From impls for extract::ws::Message

These come from tungstenite but were not exposed by axum

* Add changelog entry
2022-09-26 19:07:12 +00:00
Jonas Platte
9196c09fe8
Merge handler::{WithState, IntoService} into one HandlerService type (#1418) 2022-09-26 14:51:42 +02:00
Logan Keenan
31638a2b22
Add tokio feature & make tokio optional for WASM support (#1382)
* add server feature and make tokio and hyper/server and tcp optional

* address review comments

* don't mention any specific runtimes in the example

* sort deps

* add `tokio` feature when adding `ws`

* don't always pull in tower feature that pulls in tokio io stuff

* remove usage of `tokio_cr`

* changelog

* depend on tokio version that supports wasm

* don't make it sound like tokio doesn't support wasm

* call out new default feature

Co-authored-by: Fisher Darling <fdarlingco@gmail.com>
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-09-25 15:10:33 +00:00
Jonas Platte
83ba8c3876
Remove *_boxed_response_body methods on MethodRouter (#1415)
They were identical to the methods without the prefix.
2022-09-25 16:26:18 +02:00
David Pedersen
04ef2f1bc0
Add map_response and friends (#1414)
* Add `map_response` and friends

* changelog
2022-09-25 16:21:30 +02:00
David Pedersen
0e4a894c16 Fix formatting of one more macro 2022-09-25 15:26:36 +02:00
David Pedersen
bf341fd034
Refactor all_the_tuples! macros (#1413) 2022-09-25 15:22:40 +02:00
David Pedersen
8dd9c8d286 Add missing changelog PR links 2022-09-25 14:41:15 +02:00
Jonas Platte
4847d681b1
Allow Routers to inherit state (#1368)
* Rename Fallback::Custom to Fallback::Service

* Allow Routers to inherit state

* Rename Router::{nest => nest_service} and add new nest method for Routers

* Fix lints

* Add basic tests for state inheritance

* Changelog
2022-09-25 11:56:23 +00:00
David Pedersen
2077d50021
Add map_request and friends (#1408)
* Add `map_request` and friends

* finish it

* changelog ref

* Apply suggestions from code review

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

* address review feedback

* Apply suggestions from code review

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

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-09-25 11:44:10 +00:00
Marek Kuskowski
896ffc5fba
Remove ContentLengthLimit (#1400)
* feat: remove ContentLengthLimit

* feat: remove ContentLengthLimit rejections

* fix: update multipart docs

* fix: typo

* feat: add wip extractor code

* feat: revert "feat: add wip extractor code"

* fix: update Multipart docs

* fix: update examples

* fix: missing import in an example

* fix: broken import yet again

* fix: disable default body limit for example

* fix: key value store example

* fix: update expected debug_handler output

* chore: update CHANGELOG

* Update axum/CHANGELOG.md

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-09-24 11:29:53 +00:00
Jonas Platte
e3a17c1249
Add #[track_caller] attribute to Router::into_[make_]service (#1407) 2022-09-23 21:10:08 +02:00
Jonas Platte
69d64cecc3
Split RouterService off of Router (#1381) 2022-09-22 12:10:55 +02:00
Jonas Platte
18e3fac5d3
Small routing module refactoring (#1364) 2022-09-22 12:10:32 +02:00
David Pedersen
611c50ec8b
Add middleware::from_extractor_with_state (#1396)
Fixes https://github.com/tokio-rs/axum/issues/1373
2022-09-20 10:13:06 +02:00
David Pedersen
de9909d955
Add DefaultBodyLimit::max to change the body size limit (#1397) 2022-09-19 22:41:54 +02:00
Jonas Platte
7105805ba2
Extend from_fn_with_state doctest (#1393) 2022-09-19 21:02:43 +02:00
David Pedersen
c93d7c324e Fix typo in docs 2022-09-18 22:24:11 +02:00
David Pedersen
21876fcc64
Clarify Clone requirements for using State (#1388) 2022-09-18 22:22:47 +02:00
David Pedersen
c81549d95b
Support streaming/chunked requests in ContentLengthLimit (#1389)
* Support streaming/chunked requests in `ContentLengthLimit`

* changelog
2022-09-18 20:21:38 +00:00
David Pedersen
8e52c5246f
Use 400 Bad Request for FailedToDeserializeQueryString rejections (#1387)
* Use `400 Bad Request` for `FailedToDeserializeQueryString` rejections

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

From [the spec] about `422 Unprocessable Entity`:

> For example, this error condition may occur if an XML request body
> contains well-formed (i.e., syntactically correct), but semantically
> erroneous, XML instructions.

I understand this to mean that query params shouldn't use 422 because
that is about the request body.

So this changes `FailedToDeserializeQueryString` from `422 Unprocessable
Entity` to `400 Bad Request`.

[the spec]: https://datatracker.ietf.org/doc/html/rfc4918#section-11.2

* changelog
2022-09-18 21:32:47 +02:00
Ferenc Tamás
84f58ae9a5
expose FromRequest and FromRequestParts macros in axum (#1352) 2022-09-18 19:46:04 +02:00
Jonas Platte
c09ecefcab
Use regular non-exhaustive debug representation instead of custom one (#1380) 2022-09-16 22:56:25 +02:00
Jonas Platte
c8dbe5a7e9
Relax Multipart FromRequest implementation bounds (#1379) 2022-09-16 18:49:42 +00:00
Hong Minhee (洪 民憙)
7476dd08cb
Show the errored path on JsonDataError (#1371)
Previously, it was difficult to find out the path in the deep JSON tree at
which a deserialization error occurred.  This patch makes an error message
to contain the errored path.  In order to find out the path,
I added serde_path_to_error, a new optional dependency.

Co-authored-by: Lee Dogeon <dev.moreal@gmail.com>

Co-authored-by: Lee Dogeon <dev.moreal@gmail.com>
2022-09-13 17:52:16 +02:00
David Pedersen
54d8439e35
Ship rc.2 (#1363)
* rc.2

* don't bump version of axum-macros

* fix

* Update axum/Cargo.toml

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

* undo release of axum-extra

* fix

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-09-11 16:42:04 +02:00
David Pedersen
759e988747
Limit size of request bodies in Bytes extractor (#1346)
* Apply default limit to request body size

* Support disabling the default limit

* docs

* changelog
2022-09-10 06:36:30 +00:00
Fredrik Meringdal
c6be977612
Fix docs for chained method routing (#1355) 2022-09-08 19:26:47 +00:00
Jonas Platte
da4ea4d4c2
Add must_use attribute to Redirect type (#1356) 2022-09-07 13:52:58 +02:00
David Pedersen
4c9edb4cd4
Add middleware::{from_fn_with_state, from_fn_with_state_arc} (#1342) 2022-08-31 18:28:54 +00:00
David Pedersen
3f92f7d254
Improve opaque error message for Handler::layer (#1336) 2022-08-28 22:17:05 +02:00
valkyrie_pilot
805463c2ef
Fix docs typo (#1334) 2022-08-27 08:01:23 +00:00
Chris Glass
b2ed55bd1f
Added notes about extractor precedence (#1324)
* [doc] Added notes about extractor precedence

Both JSON and Form extractors consume the Body when they run, so they
need to be last in the order of extractors.
Added a note in the structs docs themselves pointing to the relevant
part of the documentation.

* Address review comments

- Added documentation snippet to  BodyStream, RawBody, Multipart
- Added documentation about the inner type of ContentLengthLimit
- Fixed link type in State

* Update axum/src/extract/content_length_limit.rs

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

* Cargo fmt didn't run for some reason

I need to check my editor config...

* Apply suggestions from code review

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

* Add targets to links

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-08-26 13:02:04 +02:00
David Pedersen
eb6451c4fe
Clarify Clone requirements even if using Router::with_state_arc (#1329) 2022-08-26 07:42:32 +00:00
David Pedersen
eaabdb3973
Update out of date Router::nest docs (#1328) 2022-08-25 23:35:38 +02:00
Jonas Platte
92f6b68390
Panic when attempting to add a route_layer to an empty router (#1327) 2022-08-25 15:42:17 +02:00
Yann Simon
426b9f91e8
FromRequestParts does not have a 'B' type (#1315) 2022-08-24 09:56:02 +00:00
Chris Glass
d0b4c9032e
Explicitely point out example's dependency (#1312)
* Explicitely point out example dependency

Save the next visitor to that docs page the trouble of having to figure
out why a Path<Uuid> extractor results in a cryptic error by default.

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

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

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-08-24 07:39:41 +00:00
David Pedersen
169e2f7c24
Mention FromRef, not From, in State docs (#1311) 2022-08-24 00:10:51 +02:00
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
db08419a3b
Tweak layer and route_layer docs (#1307) 2022-08-23 16:56:24 +00:00
David Pedersen
0e04260a27
Show path in panic message when merging overlapping MethodRouters (#1306) 2022-08-23 16:32:34 +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
e3ebb62c3f
Document limitation with implementing both FromRequest and FromRequestParts (#1300)
* Document limitation with implementing both `FromRequest` and `FromRequestParts`

* Add mention about "Wrapping extractors" section
2022-08-22 18:01:56 +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
e7f1c88cd4
Always store state in an Arc (#1270)
* Add extension and state benchmarks

* wip

* Arc the state everywhere

* don't require `S: Clone`

* fix example
2022-08-17 20:08:24 +00: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
90dbd52ee4
Fix lint warnings (#1267) 2022-08-17 09:41:52 +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
David Pedersen
0090d007c0 Fix benchmark filtering 2022-08-11 11:12:04 +02:00
David Pedersen
9e50bf16fb
Add initial benchmarks (#1243)
* Add initial benchmarks

* improve error message if rewrk isn't installed

* what env vars does github ci have?

* run benchmarks for a bit on ci

* debug error

* ignore args on ci

* actually also locally

* apply review suggestions
2022-08-11 08:52:23 +00:00
Filip Kieres
7faf059234
Document browsers ignoring SSE events without data fields (#1242) (#1214) 2022-08-10 17:14:42 +02:00
David Pedersen
c72ee6eca9
Document browsers ignoring SSE events without data fields (#1242)
* Document browsers ignoring SSE events without data fields

* only add note on `Event::data`
2022-08-10 10:40:31 +00:00
David Pedersen
9b44654c86
Add "Ordering" link to middleware table of contents (#1241)
Seems I forgot to add it.
2022-08-10 12:34:05 +02: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
Mark Tuddenham
ad7c8c5cdb
docs: use local variable in closure (#1232)
The "Using closure captures for shared state" example creates two clones
when only one is needed.
2022-08-09 16:23:16 +02:00
Jonas Platte
f0f60681ef
Fix intra-doc links on docs.rs (#1205)
* Use version 2 of Cargo's feature resolver

* Increase minimum version of tungstenite

Tungstenite 0.17.1 has a higher MSRV, and there should be no reason to
use it over 0.17.2.

* Clean up and fix MSRV CI job

* Fix some intra-doc links not resolving correctly on docs.rs

* Bump minimum version of tower

… to avoid dependencies with a broken minimum-versions chain.
2022-07-28 19:14:31 +02:00
Jonas Platte
141198ce19
Declare MSRV in Cargo manifests, not .clippy.toml (#1206) 2022-07-28 15:31:47 +02:00
Ryan Fowler
7e7a2f2058
Create BytesMut for Json with initial capacity (#1196)
* Create BytesMut for Json with initial capacity

* Add a comment explaining BytesMut initial capacity

* Update link to serde_json::to_vec function to docs.rs
2022-07-26 16:45:58 +02:00
David Pedersen
234c8ccb13
Improve build times by generating less IR (#1192)
* example

* `MethodRouter::merge`

* `set_content_length` and `set_allow_header`

* `MethodRouter::on_service_boxed_response_body`

* `Router::route`

* `MethodRouter::merge` again

* `MethodRouter::on_service_boxed_response_body`

* `Router::call_route`

* `MethodRouter::{layer, route_layer}`

* revert example

* fix test

* move function to method on `AllowHeader`
2022-07-25 18:06:37 +00:00
Marek Kuskowski
1ace8554ce
Add ws example showing how to pass data to callback (#1185) 2022-07-23 16:27:36 +00:00
Jonas Platte
a3cf025d54
Serialize Json<T> to Bytes instead of Vec<u8> in IntoResponse (#1178) 2022-07-20 16:32:08 +00: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
bed0b83421 Add http-server as crates.io subcategory 2022-07-10 14:28:11 +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
David Pedersen
f8c8f5b697 Add note about breaking changes to readme 2022-07-02 11:46:53 +02:00
David Pedersen
eff3b716d3
Document running extractors from middleware (#1140)
Fixes #1134
2022-07-02 09:44:17 +00: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
f6b1d35c51
Use minimal dependency versions for MSRV tests on CI (#1109) 2022-06-27 20:44:20 +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
7deaff7e1e
axum-core: Version 0.2.6 (#1103) 2022-06-18 11:00:19 +02:00
Jonas Platte
1812c4dfe8
Remove explicit TryFrom, TryInto imports (#1099) 2022-06-17 18:36:49 +00: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
ad67289226
Add table of contents to some modules (#1084) 2022-06-14 14:10:04 +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
f66893fbda Add missing version for serde_json in Cargo.toml
No idea how that went away
2022-06-10 16:57:53 +02:00
David Pedersen
968ee44631
Sort dependencies in Cargo.tomls (#1076)
* sort dependencies

* check sorted deps on CI

* this should fail

* does caching matter?

* fix sorting
2022-06-10 08:59:17 +02:00
David Pedersen
453202b490
Document all cargo features (#1079) 2022-06-10 08:46:09 +02:00
David Pedersen
b6a2d9dba7 Use consistent todo comment casing 2022-06-09 20:47:23 +02:00
David Pedersen
7aa3f35129
axum: Version 0.5.7 (#1075) 2022-06-08 16:08:11 +02:00
David Pedersen
a9eb4ac527
axum-core: Version 0.2.5 (#1073) 2022-06-08 15:56:56 +02:00
David Pedersen
ef750799fa
Automatically handle http_body::LengthLimitError (#1048)
* Automatically handle `http_body::LengthLimitError`

* add tower-http dev dep to axum-core

* just make it a link

* Make `FailedToBufferBody` an enum

* Fix tests now that tower-http handles `Content-Length`

* Bring back explanation for `LengthLimitError`

* remove todo we likely can't fix

* improve wording in docs
2022-06-08 13:47:57 +00:00
David Pedersen
115a47b191
Remove tower's buffer feature (#1071)
Turns out we're not using it anymore and it saves depending on tokio-util.
2022-06-08 07:58:56 +00: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
Luca Barbato
bdfa3887f1
Fix a typo (#1064) 2022-06-03 08:30:48 +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
David Pedersen
19fe93262f
Use impl IntoResponse less in docs (#1049) 2022-05-22 13:41:29 +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
Kosta
d37b93a3c4
Dont link to deprecated item with different name (#1028) 2022-05-12 12:06:13 +00:00
David Pedersen
0b856b938f
Document "debugging handler type errors" on Handler (#1024) 2022-05-11 20:56:57 +02: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
2353ee788c
Make docs around extracting Request more explicit (#1013) 2022-05-10 11:00:57 +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
lz1998
b8514cf1c2
Update LICENSE (#1006) 2022-05-07 16:20:07 +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
takumi
4b384fa01c
upgrade uuid from 0.8 to 1.0 (#995) 2022-05-05 07:48:49 +02:00
Conrad
002cff5c79
fix link about backpressure from routing section (#993) 2022-05-04 06:07:24 +00:00
Thomas Scholtes
8cc052f38b
Make Path extractor work with Deserialize impls using &str (#990)
* `Path` extractor works with `Deserialize` impls using `&str`

Before this change the extractor `Path<Test>` would fail if the
`Deserialize` implementation of `Test` was calling
`Deserializer::deserialize_str()`.

Now we use `Visitor::visit_borrowed_str()` instead of
`Visitor::visit_str()` which is also recommended in the guide to
implement a deserializer [1].

[1]: https://serde.rs/impl-deserializer.html

* fixup! `Path` extractor works with `Deserialize` impls using `&str`

* add test for percent decoding

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-05-03 18:44:58 +00:00
Gabriel Lacroix
d2fab9245b
Fix some typos and grammatical mistakes (#986) 2022-05-03 06:30:17 +00:00
David Pedersen
5be73c1064
axum-core: Version 0.2.4 (#984) 2022-05-02 11:52:24 +02:00
David Pedersen
8dd6070574
Implement IntoResponse for (Parts | Request<()>, $(impl IntoResponseParts)+, impl IntoResponse) (#980)
* Implement `IntoResponse for (Parts | Request<()>, $(impl IntoResponseParts)+, impl IntoResponse)`

Fixes #979

* changelog

* docs

* changelog ref
2022-04-29 22:08:47 +02:00
David Pedersen
a723ed1453
axum: Version 0.5.4 (#973) 2022-04-26 16:50:44 +02:00
David Pedersen
0702c59c7d
axum-core: Version 0.2.3 (#966) 2022-04-26 14:19:47 +00:00
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
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
Nahua
cb6fea37af
Edit readme to make community projects stand out as examples (#956) 2022-04-24 12:49:15 +02: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
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
zys864
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 <zys864@gmail.com>
2022-04-09 18:33:44 +02:00
zys864
f13eab893a
fix route module clippy warnings (#920)
Co-authored-by: zys864 <zys864@gmail.com>
2022-04-08 14:28:11 +02: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
David Pedersen
405e3f8c44
Add SpaRouter (#904) 2022-04-03 18:29:37 +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
fba2faa38f
axum-core: Version 0.2.0 (#894) 2022-03-31 20:36:12 +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
Yotam Ofek
2e5d56a9b1
Update outdated Query extractor docs. (#891) 2022-03-31 15:43:54 +02: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
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 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
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 <nathaniel@profian.com>
2022-03-18 15:40:27 +00: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
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
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
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 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
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
Jonas Platte
89e9d1bff1
Put the Form and Query extractors behind (default-on) Cargo features (#775)
* Put the Form extractor behind a (default-activated) Cargo feature

* Put the Query behind a (default-activated) Cargo feature
2022-02-22 10:12:24 +01:00