Skip to content

Commit e6c3148

Browse files
authored
Merge pull request #52 from betagouv/do_not_chunk_forward_response
Do not chunk forward response
2 parents 88f8ed1 + df5c5be commit e6c3148

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/proxy.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ static FORWARD_REQUEST_HEADERS_TO_REMOVE: [header::HeaderName; 3] = [
2121
header::EXPECT,
2222
];
2323

24-
static FORWARD_RESPONSE_HEADERS_TO_REMOVE: [header::HeaderName; 2] = [
24+
static FORWARD_RESPONSE_HEADERS_TO_REMOVE: [header::HeaderName; 1] = [
2525
// Connection settings (keepalived) must not be resend
2626
header::CONNECTION,
27-
// Encryption changes the length of the content
28-
// and we use chunk transfert-encoding
29-
header::CONTENT_LENGTH,
3027
];
3128

3229
static FETCH_REQUEST_HEADERS_TO_REMOVE: [header::HeaderName; 1] = [
@@ -91,27 +88,26 @@ async fn forward(
9188
))
9289
};
9390

94-
forwarded_req
91+
let mut res = forwarded_req
9592
.send_stream(stream_to_send)
9693
.await
97-
.map_err(Error::from)
98-
.map(|res| {
99-
if res.status().is_client_error() || res.status().is_server_error() {
100-
error!("forward error {:?} {:?}", req, res);
101-
}
94+
.map_err(Error::from)?;
10295

103-
let mut client_resp = HttpResponse::build(res.status());
96+
if res.status().is_client_error() || res.status().is_server_error() {
97+
error!("forward error {:?} {:?}", req, res);
98+
}
10499

105-
for (header_name, header_value) in res
106-
.headers()
107-
.iter()
108-
.filter(|(h, _)| !FORWARD_RESPONSE_HEADERS_TO_REMOVE.contains(&h))
109-
{
110-
client_resp.header(header_name.clone(), header_value.clone());
111-
}
100+
let mut client_resp = HttpResponse::build(res.status());
112101

113-
client_resp.streaming(res)
114-
})
102+
for (header_name, header_value) in res
103+
.headers()
104+
.iter()
105+
.filter(|(h, _)| !FORWARD_RESPONSE_HEADERS_TO_REMOVE.contains(&h))
106+
{
107+
client_resp.header(header_name.clone(), header_value.clone());
108+
}
109+
110+
Ok(client_resp.body(res.body().await?))
115111
}
116112

117113
async fn fetch(

0 commit comments

Comments
 (0)