use crate::error::unexpected::{self}; use crate::service; use http::header::HeaderValue; use std::net; pub async fn serve_http_request( config: &service::http::ConfigProxiedDomain, client_ip: net::IpAddr, mut req: hyper::Request, req_is_https: bool, ) -> unexpected::Result> { for (name, value) in config.request_headers.as_ref() { if value == "" { req.headers_mut().remove(name); continue; } req.headers_mut().insert(name, value.clone()); } if req_is_https { req.headers_mut() .insert("x-forwarded-proto", HeaderValue::from_static("https")); } let url = config.url.as_ref(); match hyper_reverse_proxy::call(client_ip, url, req).await { Ok(res) => Ok(res), // ProxyError doesn't actually implement Error :facepalm: so we have to format the error // manually Err(e) => Err(unexpected::Error::from( format!("error while proxying to {url}: {e:?}").as_str(), )), } }