From 71c9b8dbf50ce63575b329c23ca31c494155d913 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Tue, 5 Mar 2024 21:00:02 +0100 Subject: [PATCH] Upgrade hyper-reverse-proxy to fix websocket forwarding --- Cargo.lock | 3 ++- Cargo.toml | 12 ++++++------ flake.nix | 4 ++++ src/service/http/proxy.rs | 4 +++- src/service/http/tasks.rs | 4 ++-- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06a8f40..835e159 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1051,8 +1051,9 @@ dependencies = [ [[package]] name = "hyper-reverse-proxy" version = "0.5.2-dev" -source = "git+https://code.betamike.com/micropelago/hyper-reverse-proxy.git?branch=master#1dc4618994a5e9bc5de2083b911b1b08da7c081f" +source = "git+https://code.betamike.com/micropelago/hyper-reverse-proxy.git?rev=1a9e3430dd7a9d3579ebe183abed6596a414c5bf#1a9e3430dd7a9d3579ebe183abed6596a414c5bf" dependencies = [ + "http-body-util", "hyper 1.2.0", "hyper-util", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index 89a013d..394fdcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,8 +3,6 @@ name = "domani" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dev-dependencies] tempdir = "0.3.7" @@ -37,7 +35,6 @@ log = "0.4.19" env_logger = "0.10.0" serde_yaml = "0.9.22" rand = "0.8.5" -hyper-reverse-proxy = "0.5.2-dev" gemini = "0.0.5" bytes = "1.4.0" gix-hash = "0.14.1" @@ -49,11 +46,14 @@ http-body-util = "0.1.0" http-body = "1.0.0" awaitgroup = "0.7.0" +# The micropelago fork of hyper-reverse-proxy supports hyper v1, and fixes some +# bugs from upstream (which appears to be unmaintained). +[dependencies.hyper-reverse-proxy] +git = "https://code.betamike.com/micropelago/hyper-reverse-proxy.git" +rev = "1a9e3430dd7a9d3579ebe183abed6596a414c5bf" + [patch.crates-io] # The micropelago fork of tokio-rustls allows for gemini proxying tokio-rustls = { git = "https://code.betamike.com/micropelago/tokio-rustls.git", branch = "start-handshake-into-inner" } -# The micropelago fork of hyper-reverse-proxy supports hyper v1, and fixes some -# bugs from upstream (which appears to be unmaintained). -hyper-reverse-proxy = { git = "https://code.betamike.com/micropelago/hyper-reverse-proxy.git", branch = "master" } diff --git a/flake.nix b/flake.nix index 2cd6362..5124033 100644 --- a/flake.nix +++ b/flake.nix @@ -205,6 +205,10 @@ toolchain = mkToolchain buildSystem targetSystem; in pkgs.mkShell ({ + buildInputs = [ + pkgs.nmap + pkgs.websocat + ]; shellHook = '' export CARGO_HOME=$(pwd)/.cargo diff --git a/src/service/http/proxy.rs b/src/service/http/proxy.rs index 258991c..4a3ea23 100644 --- a/src/service/http/proxy.rs +++ b/src/service/http/proxy.rs @@ -15,6 +15,8 @@ pub fn new_client() -> Client { ) } +type ResponseBody = http_body_util::combinators::UnsyncBoxBody; + pub async fn serve_http_request( proxy_client: &Client, proxy_addr: &str, @@ -22,7 +24,7 @@ pub async fn serve_http_request( client_ip: net::IpAddr, mut req: hyper::Request, req_is_https: bool, -) -> unexpected::Result> { +) -> unexpected::Result> { for (name, value) in headers { if value.is_empty() { req.headers_mut().remove(name); diff --git a/src/service/http/tasks.rs b/src/service/http/tasks.rs index 7a2b6d2..06b45bb 100644 --- a/src/service/http/tasks.rs +++ b/src/service/http/tasks.rs @@ -13,7 +13,7 @@ async fn serve_conn( remote_addr: net::SocketAddr, req_is_https: bool, ) where - Conn: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + 'static, + Conn: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + Send + 'static, { log::debug!("[{remote_addr}] Handling incoming connection (is_https:{req_is_https})"); let service = crate::service::http::HyperServiceImpl::new( @@ -39,7 +39,7 @@ async fn serve_conn( .keep_alive_interval(Some(Duration::from_secs(10))) .keep_alive_timeout(Duration::from_secs(5)); - let mut conn = pin::pin!(builder.serve_connection(TokioIo::new(conn), service)); + let mut conn = pin::pin!(builder.serve_connection_with_upgrades(TokioIo::new(conn), service)); tokio::select! { res = conn.as_mut() => {