mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-24 16:17:56 +01:00
examples: Include headers into response in reqwest example (#2812)
This commit is contained in:
parent
50274725cb
commit
304cbee7c9
1 changed files with 3 additions and 1 deletions
|
@ -60,7 +60,7 @@ async fn proxy_via_reqwest(State(client): State<Client>) -> Response {
|
|||
}
|
||||
};
|
||||
|
||||
let response_builder = Response::builder().status(reqwest_response.status().as_u16());
|
||||
let mut response_builder = Response::builder().status(reqwest_response.status().as_u16());
|
||||
|
||||
// Here the mapping of headers is required due to reqwest and axum differ on the http crate versions
|
||||
let mut headers = HeaderMap::with_capacity(reqwest_response.headers().len());
|
||||
|
@ -70,6 +70,8 @@ async fn proxy_via_reqwest(State(client): State<Client>) -> Response {
|
|||
(name, value)
|
||||
}));
|
||||
|
||||
*response_builder.headers_mut().unwrap() = headers;
|
||||
|
||||
response_builder
|
||||
.body(Body::from_stream(reqwest_response.bytes_stream()))
|
||||
// This unwrap is fine because the body is empty here
|
||||
|
|
Loading…
Reference in a new issue