From 304cbee7c9efd489e53a3bb9ce4860eebe1915ba Mon Sep 17 00:00:00 2001 From: Valerio Ageno <51341197+Valerioageno@users.noreply.github.com> Date: Fri, 26 Jul 2024 19:36:45 +0200 Subject: [PATCH] examples: Include headers into response in reqwest example (#2812) --- examples/reqwest-response/src/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/reqwest-response/src/main.rs b/examples/reqwest-response/src/main.rs index b6dfeb70..cbfaae33 100644 --- a/examples/reqwest-response/src/main.rs +++ b/examples/reqwest-response/src/main.rs @@ -60,7 +60,7 @@ async fn proxy_via_reqwest(State(client): State) -> 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) -> 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