pub struct H2ReverseProxy { /* private fields */ }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
Available on crate feature http2 only.
impl Middleware for H2ReverseProxy
http2 only.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.