Skip to content

Commit

Permalink
revert proxy-san (misinterpretation of spec)
Browse files Browse the repository at this point in the history
  • Loading branch information
GlenDC committed Sep 21, 2024
1 parent 75d43bd commit 5a084c8
Showing 1 changed file with 15 additions and 42 deletions.
57 changes: 15 additions & 42 deletions rama-http-backend/src/client/svc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,48 +105,21 @@ fn sanitize_client_req_header<S, B>(

parts.uri = rama_http_types::Uri::from_parts(uri_parts)?;
Request::from_parts(parts, body)
} else if ctx.contains::<ProxyAddress>() && req.uri().host().is_none() {
// set scheme/host if not defined as that is required for proxy requests
let request_ctx = ctx.get::<RequestContext>().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
}
Expand Down

0 comments on commit 5a084c8

Please sign in to comment.