Skip to main content

Module proxy

Module proxy 

Source
Available on non-WebAssembly only.
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"));

Modules§

grpc_webhttp2
gRPC-web to gRPC: GrpcWebLayer lets browsers (which can’t read HTTP trailers or send HTTP/2 frames of their own) call gRPC services, as Envoy’s grpc_web filter 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).

Structs§

GrpcProxyhttp2
gRPC reverse proxy middleware.
GrpcWebLayer
Translates gRPC-web requests to gRPC for the layers after it — put it in front of a GrpcProxy:
H2ReverseProxyhttp2
Reverse proxy that forwards requests to HTTP/2 backends.
H3ReverseProxyhttp3
Reverse proxy that forwards requests to https:// backends over HTTP/3 (QUIC). Since 18.13.0; requires the http3 feature (default).
Pool
Per-backend HTTP/1.1 connection pool, generic over the connection type.
ReverseProxy
Reverse proxy middleware.
UpstreamTls
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§

LoadBalancing
Load balancing strategy used by ReverseProxy.

Type Aliases§

ConnPool
Per-backend HTTP/1.1 connection pool of plain TCP connections — the pool ReverseProxy::with_pool takes. (HTTPS backends use an internal Pool of TLS streams.)