pub struct H2ReverseProxy { /* private fields */ }http2 and non-WebAssembly only.Expand description
Reverse proxy that forwards requests to HTTP/2 backends.
Wraps ReverseProxy and forces HTTP/2 (h2) for all upstream connections.
Requires the http2 Cargo feature.
This proxy also transparently handles gRPC traffic
(Content-Type: application/grpc*) — gRPC DATA frames are forwarded
as-is because gRPC is layered directly on HTTP/2.
Implementations§
Source§impl H2ReverseProxy
impl H2ReverseProxy
Sourcepub fn new<I, S>(backends: I) -> H2ReverseProxy
pub fn new<I, S>(backends: I) -> H2ReverseProxy
Create a proxy distributing requests across backends in round-robin order.
Each backend entry can be:
"host:port"— plain TCP (HTTP/2 cleartext)"h2://host:port"— plain TCP (explicit scheme)"h2s://host:port"— TLS (HTTP/2 over HTTPS; port defaults to 443)"https://host:port"— TLS (same ash2s://)
TLS backends require the http2 Cargo feature (includes rustls +
webpki-roots). Certificate verification uses the WebPKI trust store.
Sourcepub fn path_prefix(self, prefix: impl Into<String>) -> H2ReverseProxy
pub fn path_prefix(self, prefix: impl Into<String>) -> H2ReverseProxy
Only proxy requests whose URI starts with prefix; pass others through.
Sourcepub fn connect_timeout_ms(self, ms: u64) -> H2ReverseProxy
pub fn connect_timeout_ms(self, ms: u64) -> H2ReverseProxy
Override the TCP connect timeout (default: 5 s).
Sourcepub fn read_timeout_ms(self, ms: u64) -> H2ReverseProxy
pub fn read_timeout_ms(self, ms: u64) -> H2ReverseProxy
Override the read timeout (default: 30 s). It bounds each wait for the upstream — the handshake, the response head, every body frame — so a streaming response (a gRPC server stream) ends only when it goes quiet for that long.
Sourcepub fn tls_ca_file(self, path: &str) -> Result<H2ReverseProxy, String>
pub fn tls_ca_file(self, path: &str) -> Result<H2ReverseProxy, String>
Trust the CA certificates in the PEM file path for h2s:// /
https:// backends instead of the WebPKI roots. Since 18.3.0.
Sourcepub fn tls_client_cert(
self,
cert: &str,
key: &str,
) -> Result<H2ReverseProxy, String>
pub fn tls_client_cert( self, cert: &str, key: &str, ) -> Result<H2ReverseProxy, String>
Present a client certificate to TLS backends that require one (mutual TLS). Since 18.3.0.
Trait Implementations§
Source§impl Middleware for H2ReverseProxy
impl Middleware for H2ReverseProxy
Source§fn accepts_streamed_body(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn accepts_streamed_body( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
Headers only: a request this proxy doesn’t forward passes through untouched.
Source§fn answers_streamed_body(
&self,
request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn answers_streamed_body( &self, request: &Request, _connection: &ConnectionInfo, ) -> bool
Requests this proxy forwards are sent as their body arrives (gRPC client streaming and bidirectional calls).
fn handle( &self, request: &Request, connection: &ConnectionInfo, next: &dyn Application, ) -> Result<Response, String>
Source§fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
true when this layer’s own work for request never blocks (in-memory
state, atomics, short mutexes) — see Application::runs_inline. A
WithMiddleware stack runs inline only if every layer and the inner
application agree. Default false.Source§fn is_passthrough(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn is_passthrough( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when handle would do nothing for request but call next
(e.g. a rate limit that isn’t configured). A WithMiddleware stack
offers the inner application’s execute_async only if every layer
passes the request through. Default false.Source§fn layer_name(&self) -> &'static str
fn layer_name(&self) -> &'static str
Application::middleware_names): by default the type’s name
without its module path or generic parameters (CacheLayer). Since
18.28.0.Auto Trait Implementations§
impl !Freeze for H2ReverseProxy
impl !RefUnwindSafe for H2ReverseProxy
impl !UnwindSafe for H2ReverseProxy
impl Send for H2ReverseProxy
impl Sync for H2ReverseProxy
impl Unpin for H2ReverseProxy
impl UnsafeUnpin for H2ReverseProxy
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
map-response-body only.Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
trace only.