Skip to content

Instantly share code, notes, and snippets.

@walkermatt
Created September 30, 2017 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walkermatt/970a1520dd4c507db57cd9c2b09b55d7 to your computer and use it in GitHub Desktop.
Save walkermatt/970a1520dd4c507db57cd9c2b09b55d7 to your computer and use it in GitHub Desktop.
""" 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):
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 = self.app(environ, 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