Skip to content

Commit

Permalink
drop sanatize logic for client svc... might give more trouble than wh…
Browse files Browse the repository at this point in the history
…at it saves us
  • Loading branch information
GlenDC committed Sep 19, 2024
1 parent 4cde0e8 commit 337e359
Showing 1 changed file with 3 additions and 43 deletions.
46 changes: 3 additions & 43 deletions rama-http-backend/src/client/svc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ use rama_core::{
error::{BoxError, OpaqueError},
Context, Service,
};
use rama_http_types::{
dep::http::uri::PathAndQuery, dep::http_body, header::HOST, headers::HeaderMapExt, Method,
Request, Response, Version,
};
use rama_net::{address::ProxyAddress, http::RequestContext};
use rama_http_types::{dep::http_body, Method, Request, Response};
use tokio::sync::Mutex;

#[derive(Debug)]
Expand Down Expand Up @@ -54,7 +50,7 @@ where
}

fn sanitize_client_req_header<S, B>(
ctx: &mut Context<S>,
_ctx: &mut Context<S>,
req: Request<B>,
) -> Result<Request<B>, BoxError> {
Ok(match req.method() {
Expand All @@ -65,42 +61,6 @@ fn sanitize_client_req_header<S, B>(
}
req
}
_ => {
// GET | HEAD | POST | PUT | DELETE | OPTIONS | TRACE | PATCH
if !ctx.contains::<ProxyAddress>()
&& req.uri().host().is_some()
&& req.version() <= Version::HTTP_11
{
// ensure request context is defined prior to doing this, as otherwise we can get issues
let _ = ctx.get_or_try_insert_with_ctx::<RequestContext, _>(|ctx| {
(ctx, &req).try_into()
})?;

tracing::trace!(
"remove authority and scheme from non-connect direct http(~1) request"
);
let (mut parts, body) = req.into_parts();
let mut uri_parts = parts.uri.into_parts();
uri_parts.scheme = None;
let authority = uri_parts
.authority
.take()
.expect("to exist due to our host existence test");
if uri_parts.path_and_query.as_ref().map(|pq| pq.as_str()) == Some("/") {
uri_parts.path_and_query = Some(PathAndQuery::from_static("/"));
}

if !parts.headers.contains_key(HOST) {
parts
.headers
.typed_insert(rama_http_types::headers::Host::from(authority));
}

parts.uri = rama_http_types::Uri::from_parts(uri_parts)?;
Request::from_parts(parts, body)
} else {
req
}
}
_ => req,
})
}

0 comments on commit 337e359

Please sign in to comment.