examples: Include headers into response in reqwest example (#2812)

This commit is contained in:
Valerio Ageno 2024-07-26 19:36:45 +02:00 committed by GitHub
parent 50274725cb
commit 304cbee7c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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