Skip to content

Commit 74d17e5

Browse files
authored
move the nginx HTTP2 bug workaround (#3239)
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 <[email protected]>
1 parent 4c36823 commit 74d17e5

File tree

1 file changed

+9
-5
lines changed
  • crates/factor-outbound-http/src

1 file changed

+9
-5
lines changed

crates/factor-outbound-http/src/wasi.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,14 @@ async fn send_request_impl(
425425
*request.uri_mut() = origin.into_uri(path_and_query);
426426
}
427427

428+
// Some servers (looking at you nginx) don't like a host header even though
429+
// http/2 allows it: https://github.com/hyperium/hyper/issues/3298.
430+
//
431+
// Note that we do this _before_ invoking the request interceptor. It may
432+
// decide to add the `host` header back in, regardless of the nginx bug, in
433+
// which case we'll let it do so without interferring.
434+
request.headers_mut().remove(HOST);
435+
428436
if let Some(interceptor) = request_interceptor {
429437
let intercept_request = std::mem::take(&mut request).into();
430438
match interceptor.intercept(intercept_request).await? {
@@ -459,7 +467,7 @@ async fn send_request_impl(
459467
}
460468

461469
async fn send_request_handler(
462-
mut request: http::Request<HyperOutgoingBody>,
470+
request: http::Request<HyperOutgoingBody>,
463471
wasmtime_wasi_http::types::OutgoingRequestConfig {
464472
use_tls,
465473
connect_timeout,
@@ -470,10 +478,6 @@ async fn send_request_handler(
470478
blocked_networks: BlockedNetworks,
471479
http_clients: HttpClients,
472480
) -> Result<wasmtime_wasi_http::types::IncomingResponse, ErrorCode> {
473-
// Some servers (looking at you nginx) don't like a host header even though
474-
// http/2 allows it: https://github.com/hyperium/hyper/issues/3298
475-
request.headers_mut().remove(HOST);
476-
477481
let resp = CONNECT_OPTIONS.scope(
478482
ConnectOptions {
479483
blocked_networks,

0 commit comments

Comments
 (0)