Skip to content

Latest commit

 

History

History

http-proxy

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

HTTP forwarding proxy

This example forwards requests to a single HTTP upstream with ntex::client::Client. The forward handler in src/main.rs preserves the request path and query, copies headers, and adds X-Forwarded-For when a peer address is available. Request and response bodies are buffered, not streamed.

Prerequisites

A reachable HTTP upstream server is required. The example below assumes one is already listening on 127.0.0.1:3000.

Run the example

cd extras/http-proxy
cargo run -- 127.0.0.1 8080 127.0.0.1 3000

With these arguments, the proxy listens on 127.0.0.1:8080 and forwards to http://127.0.0.1:3000. The four required positional arguments, in order, are listen_addr, listen_port, forward_addr, and forward_port. Keep Cargo's -- separator before them.

Try it

curl -i 'http://127.0.0.1:8080/example?name=ntex'

This forwards the request to http://127.0.0.1:3000/example?name=ntex and returns the upstream status and body. The upstream decides the response.

Tests

cargo test -p http-proxy

Covers request and response forwarding and upstream error responses using local test servers.

Learn more