pub struct ForwarderClient { /* private fields */ }Expand description
Forwarder client for sending requests to upstream backends.
Implementations§
Source§impl ForwarderClient
impl ForwarderClient
Sourcepub async fn forward(
&self,
backend: &Backend,
request: Request<BoxBody<Bytes, Error>>,
) -> Result<Response<Incoming>, ProxyError>
pub async fn forward( &self, backend: &Backend, request: Request<BoxBody<Bytes, Error>>, ) -> Result<Response<Incoming>, ProxyError>
Forward a request to a backend.
Sourcepub async fn forward_upgrade(
&self,
backend: &Backend,
request: Request<BoxBody<Bytes, Error>>,
tunnel_idle: Duration,
) -> Result<Response<BoxBody<Bytes, Error>>, ProxyError>
pub async fn forward_upgrade( &self, backend: &Backend, request: Request<BoxBody<Bytes, Error>>, tunnel_idle: Duration, ) -> Result<Response<BoxBody<Bytes, Error>>, ProxyError>
Forward a protocol-upgrade request (WebSocket) and tunnel the result.
This cannot use the pooled client: once the upstream answers 101 the connection stops being request/response and becomes an opaque byte stream, which a connection pool has no way to hand back. So dial the backend directly, keep the lower-level connection, and splice the two upgraded halves together.
HTTP/1.1 only; Self::forward_h2_websocket is the HTTP/2 spelling.
Which protocols may be upgraded to is the caller’s decision, made
before this is called: this tunnels whatever Upgrade the request
carries. The tunnel is closed after tunnel_idle with no bytes in
either direction.
Sourcepub async fn forward_h2_websocket(
&self,
backend: &Backend,
request: Request<BoxBody<Bytes, Error>>,
protocol: &str,
tunnel_idle: Duration,
) -> Result<Response<BoxBody<Bytes, Error>>, ProxyError>
pub async fn forward_h2_websocket( &self, backend: &Backend, request: Request<BoxBody<Bytes, Error>>, protocol: &str, tunnel_idle: Duration, ) -> Result<Response<BoxBody<Bytes, Error>>, ProxyError>
Forward an HTTP/2 extended CONNECT (RFC 8441) to an HTTP/1.1 WebSocket origin, translating between the two handshakes.
The two are not the same conversation, so this is a rewrite rather than a relay:
- HTTP/2 carries the intent in
:method = CONNECTand:protocol; HTTP/1.1 carries it inUpgradeplus aConnectiontoken. - HTTP/2 has no
Sec-WebSocket-Key. The nonce exists to stop an HTTP/1.1 cache from mistaking the handshake for an ordinary response, which does not apply to a multiplexed stream. The h1 origin still requires one, so the proxy generates it here. - Success is
101on the wire to the origin but200back to the client; a 101 has no meaning on an HTTP/2 stream.
The origin’s Sec-WebSocket-Accept is not verified against the generated
key. Status 101 plus a websocket Upgrade is taken as sufficient, which
avoids a SHA-1 dependency for a check that guards against a
misconfigured origin rather than an attacker.
As with Self::forward_upgrade, whether protocol is allowed is for
the caller to decide first.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ForwarderClient
impl !UnwindSafe for ForwarderClient
impl Freeze for ForwarderClient
impl Send for ForwarderClient
impl Sync for ForwarderClient
impl Unpin for ForwarderClient
impl UnsafeUnpin for ForwarderClient
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