Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Reverse Proxy

TezWeb supports reverse proxying with automatic prefix stripping.

Basic Usage

use tezweb::TezWeb;

#[tokio::main]
async fn main() {
    TezWeb::new()
        .port(8080)
        .proxy("/api", "http://localhost:9000")
        .run()
        .await
        .unwrap();
}

How Prefix Stripping Works

A request to /api/users is forwarded to the backend as /users — the /api prefix is stripped automatically.

Incoming RequestForwarded To
/api/usershttp://localhost:9000/users
/api/datahttp://localhost:9000/data
/api/http://localhost:9000/

Multiple Proxy Rules

#![allow(unused)]
fn main() {
TezWeb::new()
    .proxy("/api", "http://localhost:9000")
    .proxy("/auth", "http://localhost:9001")
    .run()
    .await
    .unwrap();
}

Testing

cargo run --example proxy_test

Then in another terminal:

python3 -m http.server 9000
curl http://localhost:8080/api/somefile

Implementation Notes

The proxy opens a raw TCP connection to the target, forwards the HTTP request with the stripped path, and streams the response back to the client. Connection header is set to close for simplicity.

Verified

Prefix stripping was tested end-to-end — /api/somefile correctly forwards to the backend as /somefile.