mirror of
https://github.com/tokio-rs/axum.git
synced 2024-12-01 20:50:46 +01:00
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.
This commit is contained in:
parent
ccd7bd91a6
commit
e781b7b936
1 changed files with 4 additions and 32 deletions
|
@ -136,38 +136,10 @@ async fn get_user_things(
|
||||||
# };
|
# };
|
||||||
```
|
```
|
||||||
|
|
||||||
Take care of the order in which you apply extractors as some extractors
|
Take care of the order in which you apply extractors as some will mutate the
|
||||||
mutate the request.
|
request. For example extractors that consume the request body can only be
|
||||||
|
applied once. The same is true for [`Request`], which consumes the entire
|
||||||
For example using [`HeaderMap`] as an extractor will make the headers
|
request:
|
||||||
inaccessible for other extractors on the handler. If you need to extract
|
|
||||||
individual headers _and_ a [`HeaderMap`] make sure to apply the extractor of
|
|
||||||
individual headers first:
|
|
||||||
|
|
||||||
```rust,no_run
|
|
||||||
use axum::{
|
|
||||||
extract::TypedHeader,
|
|
||||||
routing::get,
|
|
||||||
headers::UserAgent,
|
|
||||||
http::header::HeaderMap,
|
|
||||||
Router,
|
|
||||||
};
|
|
||||||
|
|
||||||
async fn handler(
|
|
||||||
TypedHeader(user_agent): TypedHeader<UserAgent>,
|
|
||||||
all_headers: HeaderMap,
|
|
||||||
) {
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
|
|
||||||
let app = Router::new().route("/", get(handler));
|
|
||||||
# async {
|
|
||||||
# axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
|
||||||
# };
|
|
||||||
```
|
|
||||||
|
|
||||||
Extractors that consume the request body can also only be applied once as
|
|
||||||
well as [`Request`], which consumes the entire request:
|
|
||||||
|
|
||||||
```rust,no_run
|
```rust,no_run
|
||||||
use axum::{
|
use axum::{
|
||||||
|
|
Loading…
Reference in a new issue