Skip to main content

Module proxy

Module proxy 

Source
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"));

Structs§

GrpcProxy
gRPC reverse proxy middleware.
H2ReverseProxy
Reverse proxy that forwards requests to HTTP/2 backends.
ReverseProxy
Reverse proxy middleware.

Enums§

LoadBalancing
Load balancing strategy used by ReverseProxy.