From 5d43fa02850c12f3634f6f64e838b596eb1a6840 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 20 Aug 2025 13:43:59 -0600 Subject: [PATCH] move the nginx HTTP2 bug workaround We remove the `host` header from the request if present because (some versions of?) nginx have a known bug such that they can't handle `host` headers in HTTP/2 requests. However, the request interceptor, if present, may have its own opinions about whether a `host` header should be set, and if it insists on setting one we should honor that. So I've moved the workaround to run _before_ the interceptor is run. Signed-off-by: Joel Dice --- crates/factor-outbound-http/src/wasi.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/factor-outbound-http/src/wasi.rs b/crates/factor-outbound-http/src/wasi.rs index 4d16b83019..68cbac3b91 100644 --- a/crates/factor-outbound-http/src/wasi.rs +++ b/crates/factor-outbound-http/src/wasi.rs @@ -425,6 +425,14 @@ async fn send_request_impl( *request.uri_mut() = origin.into_uri(path_and_query); } + // Some servers (looking at you nginx) don't like a host header even though + // http/2 allows it: https://github.com/hyperium/hyper/issues/3298. + // + // Note that we do this _before_ invoking the request interceptor. It may + // decide to add the `host` header back in, regardless of the nginx bug, in + // which case we'll let it do so without interferring. + request.headers_mut().remove(HOST); + if let Some(interceptor) = request_interceptor { let intercept_request = std::mem::take(&mut request).into(); match interceptor.intercept(intercept_request).await? { @@ -459,7 +467,7 @@ async fn send_request_impl( } async fn send_request_handler( - mut request: http::Request, + request: http::Request, wasmtime_wasi_http::types::OutgoingRequestConfig { use_tls, connect_timeout, @@ -470,10 +478,6 @@ async fn send_request_handler( blocked_networks: BlockedNetworks, http_clients: HttpClients, ) -> Result { - // Some servers (looking at you nginx) don't like a host header even though - // http/2 allows it: https://github.com/hyperium/hyper/issues/3298 - request.headers_mut().remove(HOST); - let resp = CONNECT_OPTIONS.scope( ConnectOptions { blocked_networks,