pub struct H3ReverseProxy { /* private fields */ }http3 and non-WebAssembly only.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
impl Middleware for H3ReverseProxy
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.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 H3ReverseProxy
impl !RefUnwindSafe for H3ReverseProxy
impl !UnwindSafe for H3ReverseProxy
impl Send for H3ReverseProxy
impl Sync for H3ReverseProxy
impl Unpin for H3ReverseProxy
impl UnsafeUnpin for H3ReverseProxy
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.