[z3-checkins] r51928 - z3/deliverance/DeliveranceVHoster/trunk/dvhoster

ianb at codespeak.net ianb at codespeak.net
Thu Feb 28 22:35:40 CET 2008


Author: ianb
Date: Thu Feb 28 22:35:38 2008
New Revision: 51928

Modified:
   z3/deliverance/DeliveranceVHoster/trunk/dvhoster/scrubber.py
Log:
Add a fixup for the incoming request, that translates X-Forwarded-Scheme to wsgi.url_scheme, and translates X-Forwarded-Port to SERVER_PORT and the port portion of HTTP_HOST

Modified: z3/deliverance/DeliveranceVHoster/trunk/dvhoster/scrubber.py
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/dvhoster/scrubber.py	(original)
+++ z3/deliverance/DeliveranceVHoster/trunk/dvhoster/scrubber.py	Thu Feb 28 22:35:38 2008
@@ -26,8 +26,17 @@
 
     def __call__(self, environ, start_response):
         self.clean_environ_headers(environ)
+        self.fixup_forwarded_headers(environ)
         return self.app(environ, start_response)
 
+    def fixup_forwarded_headers(self, environ):
+        if 'HTTP_X_FORWARDED_SCHEME' in environ:
+            environ['wsgi.url_scheme'] = environ.pop('HTTP_X_FORWARDED_SCHEME')
+        if 'HTTP_X_FORWARDED_PORT' in environ:
+            port = environ.pop('HTTP_X_FORWARDED_PORT')
+            environ['SERVER_PORT'] = port
+            http_host = environ['HTTP_HOST'].split(':', 1)[0]
+            environ['HTTP_HOST'] = '%s:%s' % (http_host, port)
 
     def clean_environ_headers(self, environ):
         """


More information about the z3-checkins mailing list