Skip to content

Commit

Permalink
fixed #747 - don't include port in x-forwarded-for
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Apr 24, 2023
1 parent 83be017 commit f13a22f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions warpgate-protocol-http/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,14 @@ fn copy_server_request<B: SomeRequestBuilder>(req: &Request, mut target: B) -> B

fn inject_forwarding_headers<B: SomeRequestBuilder>(req: &Request, mut target: B) -> Result<B> {
if let Some(host) = req.headers().get(http::header::HOST) {
target = target.header(X_FORWARDED_HOST.clone(), host.to_str()?.to_string());
target = target.header(
X_FORWARDED_HOST.clone(),
host.to_str()?.split(':').next().unwrap().to_string(),
);
}
target = target.header(X_FORWARDED_PROTO.clone(), req.scheme().as_str().to_owned());
if let Some(addr) = req.remote_addr().as_socket_addr() {
target = target.header(X_FORWARDED_FOR.clone(), addr.to_string());
target = target.header(X_FORWARDED_FOR.clone(), addr.ip().to_string());
}
Ok(target)
}
Expand Down

0 comments on commit f13a22f

Please sign in to comment.