Commit Graph
337 Commits
Author SHA1 Message Date
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
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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: David Pedersen <[email protected]>
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 PedersenandJonas Platte 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 <[email protected]>

Co-authored-by: Jonas Platte <[email protected]>
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
danielvschoorandDavid Pedersen 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 <[email protected]>
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 PedersenandJonas Platte e39d053d2f New release candidates (#1514)
* New release candidates

* Update axum/Cargo.toml

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

Co-authored-by: Jonas Platte <[email protected]>
2022-11-09 09:01:47 +01:00
David PedersenandJonas Platte 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 <[email protected]>

* Add test for nested handler service

* change to `debug_assert`

* apply suggestions from review

Co-authored-by: Jonas Platte <[email protected]>
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 PedersenandJonas Platte 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 <[email protected]>

Co-authored-by: Jonas Platte <[email protected]>
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 KuskowskiandDavid Pedersen 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 <[email protected]>
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 PlatteandDavid Pedersen 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 <[email protected]>
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
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 <[email protected]>
Co-authored-by: David Pedersen <[email protected]>
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 PedersenandJonas Platte 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 <[email protected]>

* address review feedback

* Apply suggestions from code review

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

Co-authored-by: Jonas Platte <[email protected]>
2022-09-25 11:44:10 +00:00