HTTP Proxy Server

The code for this example is located in the examples.proxyserver.manage module.

An asynchronous multi-process HTTP proxy server. It works for both http and https (tunneled) requests.

Managing Headers

It is possible to add middleware to manipulate the original request headers. If the header middleware is an empty list, the proxy passes requests and responses unmodified. This is an implementation for a forward-proxy which can be used to retrieve any type of source from the Internet.

To run the server:


An header middleware is a callable which receives the wsgi environ and the list of request headers. By default the example uses:

examples.proxyserver.manage.x_forwarded_for(environ, headers)[source]

Add x-forwarded-for header

To run with different headers middleware create a new script and do:

from proxyserver.manage import server

if __name__ == '__main__':


class examples.proxyserver.manage.ProxyServerWsgiHandler(headers_middleware=None)[source]

WSGI middleware for an asynchronous proxy server.

To perform processing on headers you can pass a list of headers_middleware. An headers middleware is a callable which accepts two parameters, the wsgi environ dictionary and the headers container.


The HttpClient used by this proxy middleware for accessing upstream resources