Do not set Host header in proxied request

If there is a reverse proxy downstream of hyper-reverse-proxy, and
the forward_url is something like `http://127.0.0.1:4333`, with the
expectation that the downstream RP will handle the request further, then
the request ends up with `Host: 127.0.0.1` as a header, which is
incorrect. It's seemingly impossible to override this behavior.

Removing the setting of the Host header to fix this, as it's not
necessary anyway.
This commit is contained in:
Brian Picciano 2024-01-14 17:35:03 +01:00
parent e73a76600c
commit 9f4b94724f

View File

@ -3,7 +3,7 @@
#[macro_use] #[macro_use]
extern crate tracing; extern crate tracing;
use hyper::header::{HeaderMap, HeaderName, HeaderValue, HOST}; use hyper::header::{HeaderMap, HeaderName, HeaderValue};
use hyper::http::header::{InvalidHeaderValue, ToStrError}; use hyper::http::header::{InvalidHeaderValue, ToStrError};
use hyper::http::uri::InvalidUri; use hyper::http::uri::InvalidUri;
use hyper::upgrade::OnUpgrade; use hyper::upgrade::OnUpgrade;
@ -225,9 +225,9 @@ fn create_proxied_request<B>(
debug!("Setting headers of proxied request"); debug!("Setting headers of proxied request");
request //request
.headers_mut() // .headers_mut()
.insert(HOST, HeaderValue::from_str(uri.host().unwrap())?); // .insert(HOST, HeaderValue::from_str(uri.host().unwrap())?);
*request.uri_mut() = uri; *request.uri_mut() = uri;