From bc2b17602e45e93e56e2d2f6b7f443a16c73d34e Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 16 Apr 2019 15:03:11 -0700 Subject: [PATCH] fix proxy example --- http-full-proxy/src/main.rs | 19 +++++-------------- template_yarte/Cargo.toml | 4 ++-- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/http-full-proxy/src/main.rs b/http-full-proxy/src/main.rs index 2d7a8426..9b137bba 100644 --- a/http-full-proxy/src/main.rs +++ b/http-full-proxy/src/main.rs @@ -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) diff --git a/template_yarte/Cargo.toml b/template_yarte/Cargo.toml index f7645bc8..24eba8ec 100644 --- a/template_yarte/Cargo.toml +++ b/template_yarte/Cargo.toml @@ -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"