pub struct ReverseProxy { /* private fields */ }Expand description
Reverse proxy middleware.
Forwards incoming requests to one of the configured backends over HTTP/1.1.
On connection failure the next backend in the list is tried; when all
backends have failed the middleware returns 502 Bad Gateway.
Hop-by-hop headers are stripped before forwarding. X-Forwarded-For and
Via are added to every forwarded request.
§Limitations
- Only plain HTTP backends are supported (no TLS to the upstream).
- Chunked transfer encoding from the backend is forwarded as-is; callers
that need decoded bodies should set
Content-Lengthon the upstream.
Implementations§
Source§impl ReverseProxy
impl ReverseProxy
Sourcepub fn new<I, S>(backends: I) -> Self
pub fn new<I, S>(backends: I) -> Self
Create a proxy that distributes requests across backends in
round-robin order. Each entry must be "http://host:port" or
"host:port" (port defaults to 80).
Sourcepub fn path_prefix(self, prefix: impl Into<String>) -> Self
pub fn path_prefix(self, prefix: impl Into<String>) -> Self
Only proxy requests whose URI starts with prefix.
Other requests are passed through to the next layer in the middleware chain (or the inner application).
Sourcepub fn strategy(self, _strategy: LoadBalancing) -> Self
pub fn strategy(self, _strategy: LoadBalancing) -> Self
Override the load balancing strategy (currently only RoundRobin).
Sourcepub fn connect_timeout_ms(self, ms: u64) -> Self
pub fn connect_timeout_ms(self, ms: u64) -> Self
Override the TCP connect timeout (default: 5 000 ms).
Sourcepub fn read_timeout_ms(self, ms: u64) -> Self
pub fn read_timeout_ms(self, ms: u64) -> Self
Override the response read timeout (default: 30 000 ms).