Commit Graph
57 Commits
Author SHA1 Message Date
David Pedersen 352cf9a266 Implement Deref and DerefMut for built-in extractors (#1922) 2023-04-10 07:18:35 +00:00
Fredrik Enestad eb49ea4bc1 Fix typo in extractors docs (#1852) 2023-03-14 17:14:26 +00:00
Jonas Platte f65fa22f34 Improve tower-http doc links (#1842) 2023-03-12 11:15:58 +01:00
David Pedersen 5606ea3f9e #[must_use] all the things! (#1809) 2023-03-03 14:12:35 +01:00
valkyrie_pilotandDavid Pedersen e4c6d76bca Implement IntoResponse for [u8; N] and &'static [u8; N] (#1690)
Co-authored-by: David Pedersen <[email protected]>
2023-01-13 09:12:51 +00:00
David PedersenandJonas Platte 1aa357c879 Misc documentation improvements (#1647)
Co-authored-by: Jonas Platte <[email protected]>
2023-01-07 14:07:54 +01: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
David Pedersen eb2e933054 Expand the docs for Router::with_state (#1580) 2022-11-27 01:01:59 +01:00
David PedersenandJonas Platte 1b6780cf6c axum 0.6 and friends 🎉 (#1570)
* changelog

* bump versions

* reorder changelogs a bit

* Apply suggestions from code review

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

* Expand fallback inheritance

* Reword tsr

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

Co-authored-by: Jonas Platte <[email protected]>
2022-11-25 12:29:58 +00:00
Tshepang Mbambo 3ab3e5f91d Use http re-export in docs (#1554) 2022-11-20 21:48:41 +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 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 958d360ac4 Generalize AppendHeaders to accept any impl IntoIterator (#1495)
* Generalize `AppendHeaders` to accept any `impl IntoIterator`

* changelog
2022-10-20 21:05:04 +02:00
Jonas Platte b378fb283f Add Error::into_inner (#1476) 2022-10-13 11:44:54 +02: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 70833b9f4f Document differences between DefaultBodyLimit and RequestBodyLimit (#1461)
* Document differences between `DefaultBodyLimit` and `RequestBodyLimit`

* fix grammar

* fix accidental force push
2022-10-10 17:43:05 +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
David Pedersen bf341fd034 Refactor all_the_tuples! macros (#1413) 2022-09-25 15:22:40 +02:00
David Pedersen de9909d955 Add DefaultBodyLimit::max to change the body size limit (#1397) 2022-09-19 22:41:54 +02:00
David PedersenandJonas Platte 54d8439e35 Ship rc.2 (#1363)
* rc.2

* don't bump version of axum-macros

* fix

* Update axum/Cargo.toml

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

* undo release of axum-extra

* fix

Co-authored-by: Jonas Platte <[email protected]>
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
Liigo Zhuang f8683f37f8 Fix broken docs links (#1332) 2022-08-26 09:30:38 +00:00
David PedersenandJonas Platte 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 <[email protected]>

* 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 <[email protected]>

* remove `impl FromRequest for Either*`

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

* 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 <[email protected]>

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

* remove unused import

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

* fix trybuild expected output

Co-authored-by: Jonas Platte <[email protected]>
2022-08-22 12:23:20 +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
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 <[email protected]>
Co-authored-by: Jonas Platte <[email protected]>
2022-08-17 15:13:31 +00:00
Dominik Spicher bc55362ba8 Fix typos in RequestParts docstrings (#1147) 2022-07-08 13:26:34 +00:00
Jonas Platte 8c31bee9bc docsrs cfg fixes (#1137)
* Remove unused attribute in axum-core

* Fix docs.rs package metadata for axum-extra
2022-07-01 13:35:52 +02:00
Jonas Platte 1812c4dfe8 Remove explicit TryFrom, TryInto imports (#1099) 2022-06-17 18:36:49 +00: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 19fe93262f Use impl IntoResponse less in docs (#1049) 2022-05-22 13:41:29 +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
Marcus GriepandDavid Pedersen 6e1835074c Implement IntoResponse for Response<()> and response::Parts (#950)
* feat(axum-core): add IntoResponse for `http::response` types

* chore: narrow impl to `Response<()>`

* include extensions

* changelog

Co-authored-by: David Pedersen <[email protected]>
2022-04-29 17:52:21 +02:00
David Pedersen 5bb924b3a2 Implement IntoResponse and IntoResponseParts for http::Extensions (#975)
* Implement `IntoResponse` and `IntoResponseParts` for `http::Extensions`

Requires a new release of `http`.

* remove http patch

* changelog ref
2022-04-29 17:28:24 +02:00
8084b242d5 Add response::ErrorResponse and response::Result (#921)
* feat: add response::{Error, Result}

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

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

* misc adjustments from PR review

* Rename to `ErrorResponse` and `ResultResponse`

* nitpicky docs changes

* update changelog

* changelog wording

* Apply suggestions from code review

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

Co-authored-by: David Pedersen <[email protected]>
Co-authored-by: Jonas Platte <[email protected]>
2022-04-21 16:24:29 +02:00
David Pedersen afcefb4a70 Add AppendHeaders (#927)
* Add `AppendHeaders`

* axum changelog
2022-04-17 23:14:04 +02:00
Jonas Platte 1191b58083 Add RequestParts::extract (#897) 2022-04-01 09:25:15 +02:00
David Pedersen a0ae0c48aa Make RequestParts::body_mut return &mut Option<B> (#869) 2022-03-18 15:39:13 +00:00
David Pedersen 87a2b0dac1 Implement IntoResponseParts for Option<T> (#838) 2022-03-07 16:37:34 +01:00
David Pedersen ae22154979 Add example for implementing IntoResponseParts (#825) 2022-03-04 10:53:17 +01:00
David Pedersen 1c8f09268b Implement IntoResponseParts for more tuples (#817) 2022-03-03 08:07:00 +01: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 0d05b5e31f Remove deprecated APIs (#800)
* Remove deprecations APIs

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

* docs

* Add test

* don't allow overriding body or response

* macroify impls

* re-order things a bit

* Fix tests

* Also allow overriding version

* Move things into separate modules

* docs

* clean up

* fix trybuild test

* remove churn

* simplify buliding response

* fixup test

* fix docs typo

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

* Bring back `impl IntoResponse` in example

* Remove blanket impl to improve error message

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

* Apply suggestions from code review

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

* changelog

Co-authored-by: Jonas Platte <[email protected]>
2022-02-28 23:04:33 +00:00
Olivier PinonandDavid Pedersen d12494cc9c Add IntoResponse impl for BytesMut and Chain (#767)
* Add IntoResponse impl for BytesMut and Chain

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

* Add CHANGELOG entry

Co-authored-by: David Pedersen <[email protected]>
2022-02-17 13:30:42 +01:00
David Pedersen 208720be53 Clarity Err usage in IntoResponseHeaders 2022-01-25 09:46:38 +01:00
David Pedersen e7051322d3 Make IntoResponseHeaders members hidden 2022-01-23 20:25:12 +01:00
David Pedersen 2546be04f6 Clean up docs for IntoResponseHeaders 2022-01-23 20:25:12 +01:00
David Pedersen d4849820ce Move Headers into axum 2022-01-23 20:25:12 +01:00
Jonas Platte bf83f34617 Add trait IntoResponseHeaders (#649)
* Introduce IntoResponseHeaders trait

* Implement IntoResponseHeaders for HeaderMap

* Add impl IntoResponse for impl IntoResponseHeaders

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

* Add impl IntoResponseHeaders for Headers

… and remove IntoResponse impls that use it.

* axum-debug: Fix grammar in docs

* Explain confusing error message in docs
2022-01-23 18:01:52 +01:00