Expand description
Reverse proxy middleware with round-robin load balancing.
ReverseProxy implements Middleware — wrap any application with it and
all matching requests are forwarded to one of the configured backends over
plain HTTP/1.1. Failed backends are skipped and the next one is tried
before returning 502 Bad Gateway.
§Example
use rust_web_server::app::App;
use rust_web_server::core::New;
use rust_web_server::proxy::{LoadBalancing, ReverseProxy};
// Proxy every request across two backends in round-robin order.
let app = App::new()
.wrap(ReverseProxy::new(["http://backend-1:8080", "http://backend-2:8080"])
.strategy(LoadBalancing::RoundRobin));
// Only proxy /api/* requests; everything else is handled locally.
let app2 = App::new()
.wrap(ReverseProxy::new(["http://api-service:3000"])
.path_prefix("/api"));Re-exports§
pub use grpc_web::GrpcWebLayer;pub use pool::ConnPool;pub use pool::Pool;
Modules§
- grpc_
web - gRPC-web to gRPC:
GrpcWebLayerlets browsers (which can’t read HTTP trailers or send HTTP/2 frames of their own) call gRPC services, as Envoy’sgrpc_webfilter does. - mirror
- Request mirroring (18.11.0, #39): send a copy of a share of requests to other backends — a new version under real traffic, a shadow service — and throw the answers away.
- pool
- status
Proxy-Status(RFC 9209, 18.17.0): on every proxied response, this hop’s name and either the status it received (received-status=200) or why there was no response (error=connection_refused).- upgrade
- Upgraded connections (WebSocket) relayed to a backend (moved from the
Gateway API controller in 18.21.0; config proxy routes use it too).
Upgraded connections (WebSocket) through a proxy (a Gateway API route, or
a config-file
type = "proxy"route since 18.21.0): the request goes to the backend over its own connection; a101hands the client’s connection to a byte relay with the backend, anything else is answered as a normal response.
Structs§
- Grpc
Proxy - gRPC reverse proxy middleware.
- H2Reverse
Proxy - Reverse proxy that forwards requests to HTTP/2 backends.
- H3Reverse
Proxy - Reverse proxy that forwards requests to
https://backends over HTTP/3 (QUIC). Since 18.13.0; requires thehttp3feature (default). - Reverse
Proxy - Reverse proxy middleware.
- Upstream
Tls - Trust settings for one upstream’s TLS backends: the certificates in a CA
file instead of the WebPKI roots — for internal services behind a
private CA or a self-signed certificate (nginx’s
proxy_ssl_trusted_certificate) — and/or a client certificate rws presents to backends that require one (proxy_ssl_certificate, since 18.3.0). Connections are pooled per setting, so two upstreams at the same address with different trust never share one.
Enums§
- Load
Balancing - Load balancing strategy used by
ReverseProxy.