diff options
author | Alex Auvolat <alex@adnab.me> | 2021-12-08 13:28:07 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-12-08 13:28:07 +0100 |
commit | c49b2075a30460a319ce53da300e4943d45d5add (patch) | |
tree | 2c9e146b89873f1b79e2a7397c567e1e82299b34 /src/reverse_proxy.rs | |
parent | 35b46e64e7c9a176aeadb5815a609847bb237bb3 (diff) | |
download | tricot-c49b2075a30460a319ce53da300e4943d45d5add.tar.gz tricot-c49b2075a30460a319ce53da300e4943d45d5add.zip |
Try to fix things
Diffstat (limited to 'src/reverse_proxy.rs')
-rw-r--r-- | src/reverse_proxy.rs | 27 |
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) } |