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

fix proxy example

This commit is contained in:
Nikolay Kim 2019-04-16 15:03:11 -07:00
parent 09b0188ff9
commit bc2b17602e
2 changed files with 7 additions and 16 deletions

View File

@ -16,20 +16,11 @@ fn forward(
new_url.set_query(req.uri().query());
let forwarded_req = client.request_from(new_url.as_str(), req.head());
// if let Some(addr) = req.peer_addr() {
// match forwarded_req.headers_mut().entry("x-forwarded-for") {
// Ok(http::header::Entry::Vacant(entry)) => {
// let addr = format!("{}", addr.ip());
// entry.insert(addr.parse().unwrap());
// }
// Ok(http::header::Entry::Occupied(mut entry)) => {
// let addr = format!("{}, {}", entry.get().to_str().unwrap(), addr.ip());
// entry.insert(addr.parse().unwrap());
// }
// _ => unreachable!(),
// }
// }
let forwarded_req = if let Some(addr) = req.head().peer_addr {
forwarded_req.header("x-forwarded-for", format!("{}", addr.ip()))
} else {
forwarded_req
};
forwarded_req
.send_stream(payload)

View File

@ -19,5 +19,5 @@ yarte = { version = "0.2", features=["with-actix-web"] }
[dev-dependencies]
bytes = "0.4"
actix-http-test = "0.1.0-alpha.3"
actix-http = "0.1.0-alpha.4"
actix-http-test = "0.1.0"
actix-http = "0.1.0"