Skip to content

Commit

Permalink
Fix some out of date docs
Browse files Browse the repository at this point in the history
Since #698 this section about
`HeaderMap` removing the headers from the request is no longer true.
  • Loading branch information
davidpdrsn committed Feb 22, 2022
1 parent 113a15a commit 3752b84
Showing 1 changed file with 2 additions and 49 deletions.
51 changes: 2 additions & 49 deletions axum/src/docs/extract.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,55 +137,8 @@ async fn get_user_things(
```

Take care of the order in which you apply extractors as some extractors
mutate the request.

For example using [`HeaderMap`] as an extractor will make the headers
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
use axum::{
routing::get,
http::Request,
body::Body,
Router,
};
async fn handler(request: Request<Body>) {
// ...
}
let app = Router::new().route("/", get(handler));
# async {
# axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
# };
```
mutate the request, such as consuming the request body, which can only be done
once.

Extractors always run in the order of the function parameters that is from
left to right.
Expand Down

0 comments on commit 3752b84

Please sign in to comment.