1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00

Full proxy omit content length (#152)

* omit content-length header in http-full-proxy

* cargo fmt
This commit is contained in:
Arve Seljebu 2019-07-01 06:02:51 +02:00 committed by Nikolay Kim
parent 7c747c5006
commit 82786d4461

View File

@ -15,7 +15,9 @@ fn forward(
new_url.set_path(req.uri().path()); new_url.set_path(req.uri().path());
new_url.set_query(req.uri().query()); new_url.set_query(req.uri().query());
let forwarded_req = client.request_from(new_url.as_str(), req.head()).no_decompress(); let forwarded_req = client
.request_from(new_url.as_str(), req.head())
.no_decompress();
let forwarded_req = if let Some(addr) = req.head().peer_addr { let forwarded_req = if let Some(addr) = req.head().peer_addr {
forwarded_req.header("x-forwarded-for", format!("{}", addr.ip())) forwarded_req.header("x-forwarded-for", format!("{}", addr.ip()))
} else { } else {
@ -27,8 +29,10 @@ fn forward(
.map_err(Error::from) .map_err(Error::from)
.map(|res| { .map(|res| {
let mut client_resp = HttpResponse::build(res.status()); let mut client_resp = HttpResponse::build(res.status());
for (header_name, header_value) in for (header_name, header_value) in res
res.headers().iter().filter(|(h, _)| *h != "connection") .headers()
.iter()
.filter(|(h, _)| *h != "connection" && *h != "content-length")
{ {
client_resp.header(header_name.clone(), header_value.clone()); client_resp.header(header_name.clone(), header_value.clone());
} }