From 5a084c82ca7950f9923639ec64d1c43cde493e53 Mon Sep 17 00:00:00 2001 From: glendc Date: Sat, 21 Sep 2024 16:06:26 +0200 Subject: [PATCH] revert proxy-san (misinterpretation of spec) --- rama-http-backend/src/client/svc.rs | 57 ++++++++--------------------- 1 file changed, 15 insertions(+), 42 deletions(-) diff --git a/rama-http-backend/src/client/svc.rs b/rama-http-backend/src/client/svc.rs index 684bed37..26f5a628 100644 --- a/rama-http-backend/src/client/svc.rs +++ b/rama-http-backend/src/client/svc.rs @@ -105,48 +105,21 @@ fn sanitize_client_req_header( parts.uri = rama_http_types::Uri::from_parts(uri_parts)?; Request::from_parts(parts, body) - } else if ctx.contains::() && req.uri().host().is_none() { - // set scheme/host if not defined as that is required for proxy requests - let request_ctx = ctx.get::().ok_or_else(|| { - OpaqueError::from_display( - "[http1 proxy] add scheme/host (abs uri): missing RequestCtx", - ) - .into_boxed() - })?; - - tracing::trace!( - http_version = ?req.version(), - "defining authority and scheme to proxy http request (abs URI required here!)" - ); - - let (mut parts, body) = req.into_parts(); - let mut uri_parts = parts.uri.into_parts(); - uri_parts.scheme = Some( - request_ctx - .protocol - .as_str() - .try_into() - .context("use RequestContext.protocol as http scheme")?, - ); - - let authority: rama_http_types::dep::http::uri::Authority = request_ctx - .authority - .to_string() - .try_into() - .context("use RequestContext.authority as http authority")?; - - // add required host header if not defined - if !parts.headers.contains_key(HOST) { - parts - .headers - .typed_insert(rama_http_types::headers::Host::from(authority.clone())); - } - - uri_parts.authority = Some(authority); - parts.uri = rama_http_types::Uri::from_parts(uri_parts) - .context("create http uri from parts")?; - - Request::from_parts(parts, body) + } else if !req.headers().contains_key(HOST) { + tracing::trace!(uri = %req.uri(), "add authority as HOST header to req (was missing it)"); + let authority = req + .uri() + .authority() + .ok_or_else(|| { + OpaqueError::from_display( + "[http1] missing authority in uri and missing host", + ) + })? + .clone(); + let mut req = req; + req.headers_mut() + .typed_insert(rama_http_types::headers::Host::from(authority)); + req } else { req }