Upgrade hyper-reverse-proxy to fix websocket forwarding

This commit is contained in:
Brian Picciano 2024-03-05 21:00:02 +01:00
parent 56796e91b8
commit 71c9b8dbf5
5 changed files with 17 additions and 10 deletions

3
Cargo.lock generated
View File

@ -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",

View File

@ -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" }

View File

@ -205,6 +205,10 @@
toolchain = mkToolchain buildSystem targetSystem;
in
pkgs.mkShell ({
buildInputs = [
pkgs.nmap
pkgs.websocat
];
shellHook = ''
export CARGO_HOME=$(pwd)/.cargo

View File

@ -15,6 +15,8 @@ pub fn new_client() -> Client {
)
}
type ResponseBody = http_body_util::combinators::UnsyncBoxBody<hyper::body::Bytes, std::io::Error>;
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<Incoming>,
req_is_https: bool,
) -> unexpected::Result<hyper::Response<Incoming>> {
) -> unexpected::Result<hyper::Response<ResponseBody>> {
for (name, value) in headers {
if value.is_empty() {
req.headers_mut().remove(name);

View File

@ -13,7 +13,7 @@ async fn serve_conn<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<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() => {