* 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
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>
* Refactor proc-macro attribute parsing
* Remove `#[allow(warnings)]` which was accidentally committed
* Change span for "cannot use `rejection` without `via`" error for enums
* fix test
* [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>
* Add example for parsing body based on `Content-Type`
* format
* Update examples/parse-body-based-on-content-type/src/main.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
* fix copy/paste errors
* rename type params
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
* 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>
* Add missing leading double colon
* Separate handling of last element in FromRequest derive
* FromRequestParts derive
* fix it and add lots of tests
* docs
* changelog
* Update axum-macros/src/lib.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
* 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>
* 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>