diff options
author | metamuffin <metamuffin@disroot.org> | 2023-02-24 15:15:58 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-02-24 15:15:58 +0100 |
commit | 324b1e3bff0940a4c8af7df7b311135229a24b87 (patch) | |
tree | fcb9c76153de450cf5983398b76bee2ee984e045 /src/main.rs | |
parent | 975f2325a0ee78f75e0ed2ab899d161868250e8d (diff) | |
download | gnix-324b1e3bff0940a4c8af7df7b311135229a24b87.tar gnix-324b1e3bff0940a4c8af7df7b311135229a24b87.tar.bz2 gnix-324b1e3bff0940a4c8af7df7b311135229a24b87.tar.zst |
set server header
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index c325e61..980dd36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ use error::ServiceError; use http_body_util::{combinators::BoxBody, BodyExt}; use hyper::{ body::Incoming, - header::{CONTENT_TYPE, HOST}, + header::{CONTENT_TYPE, HOST, SERVER}, http::HeaderValue, server::conn::http1, service::service_fn, @@ -161,10 +161,24 @@ async fn service( )) .ok_or(ServiceError::NoHost)?; - match route { + let mut resp = match route { HostConfig::Backend { backend } => proxy_request(req, addr, backend).await, HostConfig::Files { files } => serve_files(req, files).await, - } + }?; + + let server_header = resp.headers().get(SERVER).cloned(); + eprintln!(" {server_header:?}"); + resp.headers_mut().insert( + SERVER, + HeaderValue::from_str(&if let Some(o) = server_header { + format!("{} via gnix", o.to_str().ok().unwrap_or("invalid")) + } else { + format!("gnix") + }) + .unwrap(), + ); + + return Ok(resp); } pub fn remove_port(s: &str) -> &str { |