pub struct MessageHandler;Expand description
Message handler for request/response manipulation.
Implementations§
Source§impl MessageHandler
impl MessageHandler
Sourcepub fn upgrade_protocol(
request: &Request<BoxBody<Bytes, Error>>,
) -> Option<String>
pub fn upgrade_protocol( request: &Request<BoxBody<Bytes, Error>>, ) -> Option<String>
The protocol a request is asking to upgrade to, if it is a valid upgrade request.
Requires both Upgrade: <proto> and an upgrade token in Connection,
per RFC 9110 section 7.8 – Upgrade alone is not a request to switch.
HTTP/2 is excluded deliberately: it carries no Upgrade header and
negotiates extended CONNECT instead (RFC 8441), which is not implemented.
Sourcepub fn h2_connect_protocol(
request: &Request<BoxBody<Bytes, Error>>,
) -> Option<String>
pub fn h2_connect_protocol( request: &Request<BoxBody<Bytes, Error>>, ) -> Option<String>
The protocol an HTTP/2 extended CONNECT is asking for (RFC 8441).
HTTP/2 has no Upgrade; a WebSocket is opened with :method = CONNECT
plus a :protocol pseudo-header, which hyper surfaces as a
hyper::ext::Protocol extension. This is only ever offered when the
listener advertised SETTINGS_ENABLE_CONNECT_PROTOCOL.
Sourcepub fn restore_upgrade_headers(
request: &mut Request<BoxBody<Bytes, Error>>,
protocol: &str,
)
pub fn restore_upgrade_headers( request: &mut Request<BoxBody<Bytes, Error>>, protocol: &str, )
Re-apply the upgrade headers that Self::strip_hop_by_hop_headers took.
An upgrade is the one case where these headers legitimately travel to the
next hop. Only a normalised Connection: upgrade and the requested
protocol go back – not whatever token list the client sent – so the
carve-out cannot be used to smuggle other headers through.
Sourcepub fn has_ambiguous_framing(request: &Request<BoxBody<Bytes, Error>>) -> bool
pub fn has_ambiguous_framing(request: &Request<BoxBody<Bytes, Error>>) -> bool
Whether the request’s body framing is ambiguous.
RFC 9112 section 6.1: a message carrying both Content-Length and
Transfer-Encoding is either a smuggling attempt or a broken client.
Transfer-Encoding wins per the spec, but a proxy that quietly
normalises the disagreement is how a smuggling chain starts, so reject
it – which is also how hyper’s own parser already treats a duplicate
Content-Length.
Must be called before Self::strip_hop_by_hop_headers, which
removes the Transfer-Encoding this inspects.
Sourcepub fn strip_hop_by_hop_headers(request: &mut Request<BoxBody<Bytes, Error>>)
pub fn strip_hop_by_hop_headers(request: &mut Request<BoxBody<Bytes, Error>>)
Remove hop-by-hop headers before forwarding, per RFC 9110 section 7.6.1.
Two sets go: the standard hop-by-hop headers, and every header named as
a token in the incoming Connection field. Call this before
Self::add_forwarding_headers – a client that names x-forwarded-for
in Connection then strips only its own inbound value, and we set a
fresh one afterwards, rather than being able to suppress ours.
Sourcepub fn add_forwarding_headers(
request: &mut Request<BoxBody<Bytes, Error>>,
client_addr: SocketAddr,
proto: &str,
)
pub fn add_forwarding_headers( request: &mut Request<BoxBody<Bytes, Error>>, client_addr: SocketAddr, proto: &str, )
Add X-Forwarded-* headers to a request.
Sourcepub fn rewrite_host_header(
request: &mut Request<BoxBody<Bytes, Error>>,
upstream_host: &str,
)
pub fn rewrite_host_header( request: &mut Request<BoxBody<Bytes, Error>>, upstream_host: &str, )
Rewrite the Host header for upstream.
Sourcepub fn strip_path_prefix(
request: &mut Request<BoxBody<Bytes, Error>>,
prefix: &str,
)
pub fn strip_path_prefix( request: &mut Request<BoxBody<Bytes, Error>>, prefix: &str, )
Strip path prefix from request URI.
Sourcepub fn apply_route_headers(
request: &mut Request<BoxBody<Bytes, Error>>,
route: &Route,
)
pub fn apply_route_headers( request: &mut Request<BoxBody<Bytes, Error>>, route: &Route, )
Apply route-specific header modifications.
Sourcepub fn error_response(
status: StatusCode,
message: &str,
) -> Response<BoxBody<Bytes, Error>>
pub fn error_response( status: StatusCode, message: &str, ) -> Response<BoxBody<Bytes, Error>>
Create a synthetic error response.
Sourcepub fn bad_request(message: &str) -> Response<BoxBody<Bytes, Error>>
pub fn bad_request(message: &str) -> Response<BoxBody<Bytes, Error>>
Create a 502 Bad Gateway response.
Sourcepub fn bad_gateway(message: &str) -> Response<BoxBody<Bytes, Error>>
pub fn bad_gateway(message: &str) -> Response<BoxBody<Bytes, Error>>
Create a 502 Bad Gateway response.
Create a 503 Service Unavailable response.
Sourcepub fn request_host(request: &Request<impl Body>) -> String
pub fn request_host(request: &Request<impl Body>) -> String
The host a request is for, without its port.
Not just the Host header. HTTP/2 has no Host: RFC 9113 section
8.3.1 replaces it with the :authority pseudo-header, which reaches us
on the URI. Reading only the header therefore yields an empty host for
every h2 and h2c request, and a route with a match.host matches
nothing – confirmed against a running proxy, where the same
host-matched route answered 200 over HTTP/1.1 and 404 over HTTP/2.
add_forwarding_headers already had this fallback for
x-forwarded-host; route selection did not.
Sourcepub fn gateway_timeout(message: &str) -> Response<BoxBody<Bytes, Error>>
pub fn gateway_timeout(message: &str) -> Response<BoxBody<Bytes, Error>>
Create a 504 Gateway Timeout response.
Takes a message so the body can say how long the request waited. A bare “Gateway Timeout” leaves the caller unable to tell a route configured with one second from an upstream that is genuinely wedged.
Auto Trait Implementations§
impl Freeze for MessageHandler
impl RefUnwindSafe for MessageHandler
impl Send for MessageHandler
impl Sync for MessageHandler
impl Unpin for MessageHandler
impl UnsafeUnpin for MessageHandler
impl UnwindSafe for MessageHandler
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more