pub struct H3ReverseProxy { /* private fields */ }Expand description
Reverse proxy that forwards requests to https:// backends over HTTP/3
(QUIC). Since 18.13.0; requires the http3 feature (default).
A backend QUIC can’t reach (UDP blocked, no handshake within the connect
timeout, a TLS failure) is sent the request over HTTPS on TCP instead,
and stays on TCP for five minutes; rws_upstream_h3_fallbacks_total
counts it under the proxy’s name.
use rust_web_server::app::App;
use rust_web_server::core::New;
use rust_web_server::proxy::H3ReverseProxy;
let proxy = H3ReverseProxy::new(["https://edge1.internal:443", "https://edge2.internal:443"])
.path_prefix("/api")
.tls_ca_file("/etc/rws/internal-ca.pem")
.unwrap();
let app = App::new().wrap(proxy);Implementations§
Source§impl H3ReverseProxy
impl H3ReverseProxy
Sourcepub fn new<I, S>(backends: I) -> H3ReverseProxy
pub fn new<I, S>(backends: I) -> H3ReverseProxy
A proxy distributing requests across backends (https://host:port,
port 443 by default) in round-robin order. Certificates are checked
against the WebPKI roots unless tls_ca_file
says otherwise. A backend that isn’t https:// is reached over
HTTP/1.1 on TCP.
Sourcepub fn name(self, name: impl Into<String>) -> H3ReverseProxy
pub fn name(self, name: impl Into<String>) -> H3ReverseProxy
The upstream label of this proxy’s fallback metric.
Sourcepub fn path_prefix(self, prefix: impl Into<String>) -> H3ReverseProxy
pub fn path_prefix(self, prefix: impl Into<String>) -> H3ReverseProxy
Only proxy requests whose URI starts with prefix; pass others through.
Sourcepub fn connect_timeout_ms(self, ms: u64) -> H3ReverseProxy
pub fn connect_timeout_ms(self, ms: u64) -> H3ReverseProxy
QUIC handshake (and TCP connect) timeout (default: 5 s).
Sourcepub fn read_timeout_ms(self, ms: u64) -> H3ReverseProxy
pub fn read_timeout_ms(self, ms: u64) -> H3ReverseProxy
Longest wait for the backend — the response head and each body chunk (default: 30 s).
Sourcepub fn tls_ca_file(self, path: &str) -> Result<H3ReverseProxy, String>
pub fn tls_ca_file(self, path: &str) -> Result<H3ReverseProxy, String>
Trust the CA certificates in the PEM file path instead of the
WebPKI roots.
Sourcepub fn tls_client_cert(
self,
cert: &str,
key: &str,
) -> Result<H3ReverseProxy, String>
pub fn tls_client_cert( self, cert: &str, key: &str, ) -> Result<H3ReverseProxy, String>
Present a client certificate to backends that require one.
Trait Implementations§
Source§impl Middleware for H3ReverseProxy
Available on crate feature http3 only.
impl Middleware for H3ReverseProxy
http3 only.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.
fn handle( &self, request: &Request, connection: &ConnectionInfo, next: &dyn Application, ) -> Result<Response, String>
Source§fn accepts_streamed_body(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn accepts_streamed_body( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when this layer never reads request.body, so the inner
application may receive it as a stream (Application::streams_body).
A layer that inspects the body (CSRF tokens in a form, request
signatures, rewriting) must keep the default false: it would see an
empty body.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.