Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
""" Minimal MapProxy Middleware demonstrating wrapping MapProxy and working
with the query string
To run:
1. Install MapProxy in a virtual enviroment together with Gunicorn
2. Create a basic MapProxy config and copy this file into the same directory as mapproxy.yaml
2. Activate virtual environment
3. Change to the directory containing this file
4. Run:
gunicorn -k eventlet --workers=1 --log-file=- mapproxy_filter:application
import urlparse
import urllib
from mapproxy.wsgiapp import make_wsgi_app
class RequestInfoFilter(object):
MapProxy middleware.
Simply prints out the environment
def __init__(self, app): = app
def __call__(self, environ, start_response):
qs = urlparse.parse_qs(environ['QUERY_STRING'], True)
print 'Original querysting: %s' % qs
# Manipulate the query string as required here...
environ['QUERY_STRING'] = urllib.urlencode(qs, True)
print 'Updated querysting passed to MapProxy: %s' % qs
content =, start_response)
return content
# Make an WSGI application and wrap it in the middleware
application = RequestInfoFilter(make_wsgi_app(r'mapproxy.yaml'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment