diff options
author | metamuffin <metamuffin@disroot.org> | 2024-08-19 13:53:05 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-08-19 13:53:05 +0200 |
commit | 7db0a67f072d212697cda117bd65d658590e279e (patch) | |
tree | bba60d66721c3343a87500dbe15c02c8afd11d2f /src/main.rs | |
parent | ad13722e62d96eb84fa72f595bf3cfd3b570155f (diff) | |
download | gnix-7db0a67f072d212697cda117bd65d658590e279e.tar gnix-7db0a67f072d212697cda117bd65d658590e279e.tar.bz2 gnix-7db0a67f072d212697cda117bd65d658590e279e.tar.zst |
remove authority from uri when translating to h1
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 14675b4..a13d171 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ use hyper::{ header::{CONTENT_TYPE, HOST, SERVER}, http::HeaderValue, service::service_fn, - Request, Response, StatusCode, + Request, Response, StatusCode, Uri, }; use hyper_util::rt::TokioExecutor; use log::{debug, error, info, warn, LevelFilter}; @@ -222,10 +222,18 @@ async fn service( mut request: Request<Incoming>, addr: SocketAddr, ) -> Result<hyper::Response<BoxBody<bytes::Bytes, ServiceError>>, ServiceError> { - // copy uri authority used in HTTP/2 to Host header field - if let Some(host) = request.uri().authority().map(|a| a.host()) { - let host = HeaderValue::from_str(host).map_err(|_| ServiceError::InvalidHeader)?; - request.headers_mut().insert(HOST, host); + // move uri authority used in HTTP/2 to Host header field + { + let uri = request.uri_mut(); + if let Some(authority) = uri.authority() { + let host = + HeaderValue::from_str(authority.host()).map_err(|_| ServiceError::InvalidUri)?; + + let mut new_uri = http::uri::Parts::default(); + new_uri.path_and_query = uri.path_and_query().cloned(); + *uri = Uri::from_parts(new_uri).map_err(|_| ServiceError::InvalidUri)?; + request.headers_mut().insert(HOST, host); + } } debug!( |