A simple reverse proxy, to be used with Hyper and Tokio.
The implementation ensures that Hop-by-hop headers are stripped correctly in both directions,
and adds the client's IP address to a comma-space-separated list of forwarding addresses in the
X-Forwarded-For
header.
The implementation is based on Go's httputil.ReverseProxy
.
Example
Because the reverse proxy needs client, we also need a Handle
. This
means that we can't take advantage of hyper's handy Http::bind
method
to quickly set up the server. Instead we do things manually:
extern crate futures;
extern crate hyper;
extern crate hyper_reverse_proxy;
extern crate tokio_core;
use Stream;
use Client;
use Http;
use ReverseProxy;
use TcpListener;
use Core;
use ;
Note that in a production system we might also want to:
- listen for
SIGINT
andSIGTERM
signals using tokio_signal - shut down the server gracefully, waiting for outstanding requests to complete
To see an example of this, look at examples/extended.rs.