Commit graph

557 commits

Author SHA1 Message Date
David Pedersen
3fb67bf79d Update changelog 2023-03-22 14:35:06 +01:00
David Pedersen
a0af61ea46
More clearly document what wildcards matches (#1873) 2023-03-22 10:48:23 +00:00
David Pedersen
03e8bc77f1
Implement IntoResponse for MultipartError (#1861) 2023-03-21 08:24:06 +00:00
David Pedersen
8e1eb8979f
Update to syn 2 (#1862) 2023-03-18 19:23:27 +00:00
David Pedersen
1133425d6b
Release axum, axum-macros, and axum-extra (#1843) 2023-03-13 11:00:13 +01:00
David Pedersen
fe9c4a0b5b
Clone state a bit less (#1837) 2023-03-12 14:43:22 +00:00
Jonas Platte
f65fa22f34
Improve tower-http doc links (#1842) 2023-03-12 11:15:58 +01:00
tottoto
5793e75aac
Change tower-http to optional (#1838) 2023-03-10 17:23:50 +01:00
David Pedersen
5c11c5c44d Print prev_route_id in impl Debug for Router 2023-03-10 12:30:08 +01:00
David Pedersen
e56e1b3e69
Don't require S: Debug for impl Debug for Router<S> (#1836) 2023-03-10 11:14:40 +00:00
Alex Butler
f9f64a3ecd
Unpin itoa dependency (#1815) 2023-03-05 14:28:10 +01:00
David Pedersen
bc3c35ea5a
Release all the crates (#1812) 2023-03-03 18:16:24 +01:00
Ingvar Stepanyan
fd96bce34d
Gracefully handle missing headers (#1810)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2023-03-03 15:35:49 +01:00
David Pedersen
5606ea3f9e
#[must_use] all the things! (#1809) 2023-03-03 14:12:35 +01:00
David Pedersen
5a58edac16
Fix routing issues when loading a Router via a dynamic library (#1806) 2023-03-03 13:23:53 +01:00
Jonas Platte
43883b8d9b
Replace weird doc paragraph by compiler-checked must_use attribute (#1801)
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2023-03-03 08:54:38 +00:00
sharkspear94
73be489e03
Fixed small typo (#1804) 2023-03-03 09:43:24 +01:00
Rob
68bf8ed7fc
Update documentation for FailedToDeserializeQueryString response type (#1795) 2023-02-27 22:29:39 +00:00
Spencer Bartholomew
6067223fcc
update tokio dep to fix potential security vulnerability (#1787) 2023-02-27 18:40:03 +01:00
David Pedersen
08bac36519
Release axum and axum-extra (#1788) 2023-02-27 09:41:11 +01:00
Robin Stocker
37e2a7d5e7
docs: Clarify that state parameters need to come before body too (#1785) 2023-02-25 10:13:32 +00:00
David Pedersen
f726f16b6d
Update to tower-http 0.4 (#1783) 2023-02-24 20:51:30 +00:00
David Pedersen
37478772bc
Release axum (#1782) 2023-02-24 14:22:47 +01:00
David Pedersen
2cbaa63d9e
Add KeepAlive::event (#1729) 2023-02-23 13:14:29 +00:00
Hugh Mandalidis
1f224396a2
Add shared mutable state documentation (#1759)
Co-authored-by: Vagelis Prokopiou <vagelis.prokopiou@gmail.com>
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2023-02-23 12:44:25 +00:00
Hugo
fa36b49769
Add hint for on further details for WebSocket (#1779) 2023-02-22 12:25:37 +00:00
David Pedersen
1e2567c39f
Fix missing Allow when middleware are applied to MethodRouter (#1773) 2023-02-20 22:54:44 +01:00
David Pedersen
277be8f813
axum 0.6.7 (#1768) 2023-02-17 15:07:23 +01:00
David Pedersen
bea84d2141 Add missing things back to changelog 2023-02-17 14:25:03 +01:00
David Pedersen
143c415955
Add MockConnectInfo (#1767) 2023-02-17 13:09:29 +01:00
David Pedersen
cd86f7ec7a
Use 422 Unprocessable Entity for Form deserialization errors, except GET and HEAD requests (#1683) 2023-02-17 09:59:02 +01:00
David Pedersen
e6ff0281ae
Try cargo public-api-crates on CI (#1761) 2023-02-16 22:41:41 +01:00
David Pedersen
c18ff9dd63
Release axum, axum-extra, and axum-macros (#1750) 2023-02-12 12:40:42 +01:00
Jonas Platte
2c9d2dea0e
Upgrade dependencies (#1746) 2023-02-11 23:36:40 +00:00
David Pedersen
0ecf5eeb19
Support passing MethodRouter to Router::fallback (#1730) 2023-02-11 23:11:55 +01:00
Cole
5c58b4ffde
Avoid unnecessary clones of state in MethodRouter (#1745) 2023-02-11 21:44:48 +00:00
David Pedersen
93ecabf449
Release axum and axum-macros (#1743) 2023-02-11 22:32:16 +01:00
David Pedersen
827140f0d7
Document gotchas with impl IntoResponse (#1736) 2023-02-07 21:28:00 +00:00
David Pedersen
6e6aa8f39e Don't use impl IntoResponse in readme 2023-02-07 17:57:28 +01:00
David Pedersen
4a5dc4391c
Release axum and axum-macros (#1721) 2023-01-24 13:31:33 +01:00
David Pedersen
47be78e0b3
Use map_while (#1720) 2023-01-24 12:49:36 +01:00
David Pedersen
6ff6b36293
Release axum and axum-core (#1716) 2023-01-20 23:51:19 +01:00
David Pedersen
5b07296001
Add RawPathParams (#1713) 2023-01-20 20:37:01 +00:00
David Pedersen
96b7d78a3f
Document required tokio features for example (#1715) 2023-01-20 20:26:40 +00:00
David Pedersen
7a52161826
Implement Clone and Service for Next (#1712) 2023-01-20 21:19:01 +01:00
Jonas Platte
7ecf8bd6cf
Use implicit format-args captures where applicable (#1709) 2023-01-20 12:04:49 +01:00
David Pedersen
8c081c20ab Remove accidentally committed dbg!s 2023-01-20 10:14:49 +01:00
David Pedersen
1be25d9496
Add internal macro to make tests of nest easier to write (#1694) 2023-01-14 14:12:01 +00:00
David Pedersen
607a20dfac
Support deserialize_any for Path (#1693) 2023-01-13 12:27:38 +00:00
David Pedersen
25a46fbe79 fixup changelog 2023-01-13 11:54:30 +01:00
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