You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1022 B
35 lines
1022 B
use crate::error::unexpected;
|
|
use std::net;
|
|
|
|
pub async fn serve_http_request(
|
|
proxy_addr: &str,
|
|
headers: &http::header::HeaderMap,
|
|
client_ip: net::IpAddr,
|
|
mut req: hyper::Request<hyper::Body>,
|
|
req_is_https: bool,
|
|
) -> unexpected::Result<hyper::Response<hyper::Body>> {
|
|
for (name, value) in headers {
|
|
if value.is_empty() {
|
|
req.headers_mut().remove(name);
|
|
continue;
|
|
}
|
|
|
|
req.headers_mut().insert(name, value.clone());
|
|
}
|
|
|
|
if req_is_https {
|
|
req.headers_mut().insert(
|
|
"x-forwarded-proto",
|
|
http::header::HeaderValue::from_static("https"),
|
|
);
|
|
}
|
|
|
|
match hyper_reverse_proxy::call(client_ip, proxy_addr, 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 {proxy_addr}: {e:?}").as_str(),
|
|
)),
|
|
}
|
|
}
|
|
|