aboutsummaryrefslogtreecommitdiff
path: root/src/reverse_proxy.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/reverse_proxy.rs')
-rw-r--r--src/reverse_proxy.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/reverse_proxy.rs b/src/reverse_proxy.rs
index 046808f..3d2a1fc 100644
--- a/src/reverse_proxy.rs
+++ b/src/reverse_proxy.rs
@@ -2,7 +2,10 @@
//! See there for original Copyright notice
use anyhow::Result;
+use log::*;
+use std::convert::TryInto;
+use http::header::HeaderName;
use hyper::header::{HeaderMap, HeaderValue};
use hyper::{Body, Client, Request, Response, Uri};
use lazy_static::lazy_static;
@@ -63,7 +66,9 @@ fn create_proxied_request<B>(
forward_url: &str,
request: Request<B>,
) -> Result<Request<B>> {
- let mut builder = Request::builder().uri(forward_uri(forward_url, &request)?);
+ let mut builder = Request::builder()
+ .method(request.method())
+ .uri(forward_uri(forward_url, &request)?);
*builder.headers_mut().unwrap() = remove_hop_headers(request.headers());
@@ -95,6 +100,21 @@ fn create_proxied_request<B>(
}
}
+ if let Some(conn) = request.headers().get("connection") {
+ if conn.to_str()?.to_lowercase() == "upgrade" {
+ if let Some(upgrade) = request.headers().get("upgrade") {
+ builder.headers_mut().unwrap().insert(
+ HeaderName::from_bytes(b"connection")?,
+ "Upgrade".try_into()?,
+ );
+ builder
+ .headers_mut()
+ .unwrap()
+ .insert(HeaderName::from_bytes(b"upgrade")?, upgrade.clone());
+ }
+ }
+ }
+
Ok(builder.body(request.into_body())?)
}
@@ -105,8 +125,13 @@ pub async fn call(
) -> Result<Response<Body>> {
let proxied_request = create_proxied_request(client_ip, &forward_uri, request)?;
+ trace!("Proxied request: {:?}", proxied_request);
+
let client = Client::new();
let response = client.request(proxied_request).await?;
+
+ trace!("Inner response: {:?}", response);
+
let proxied_response = create_proxied_response(response);
Ok(proxied_response)
}