Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Unproxy WSGI middleware

Project Description

When an HTTP proxy forwards traffic to a webserver, the server sees the proxy IP address rather than the original client IP address. Since the server may need the IP address for logging or authentication purposes, many HTTP proxies add an X-Forwarded-For header indicating the original client IP address.

As WSGI middleware, WsgiUnproxy sits between the WSGI server and your WSGI application. Before your application sees a request, WsgiUnproxy removes the X-Forwarded-For header and reinstates the client IP address, yielding a request that looks like it was never proxied to begin with.

Since anyone can add an X-Forwarded-For header, WsgiUnproxy only uses the header if it comes from a trusted proxy IP addresses.

Example WSGI application

from wsgiunproxy import unproxy

@unproxy(trusted_proxies=[ '', '' ])
def application(environ, start_response):
    start_response('200 OK', [])
    return ['Your IP address is %s.' % environ.get('REMOTE_ADDR')]

Use with Paste Deployment

WsgiUnproxy can be used in a Paste Deployment pipeline:

pipeline =

use = egg:WsgiUnproxy
trusted_proxies =,

Advanced use

If you need to specify a lot of trusted proxies (such as a whole subnet), you don’t have to use give trusted_proxies as a list. All that WsgiUnproxy asks is that trusted_proxies supports the in operator (e.g. by implementing __contains__).


To the extent possible under law, the author has waived all copyright and related or neighboring rights to WsgiUnproxy.

For more information see:

Release History

Release History

This version
History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
WsgiUnproxy-1.0.tar.gz (2.9 kB) Copy SHA256 Checksum SHA256 Source Aug 18, 2011

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting