diff pylons_app/lib/middleware/https_fixup.py @ 204:a8ea3ce3cdc4

Created middleware package. Crated special middleware to handle https requests redirections.
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 23 May 2010 00:54:22 +0200
parents
children 3782a6d698af
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pylons_app/lib/middleware/https_fixup.py	Sun May 23 00:54:22 2010 +0200
@@ -0,0 +1,21 @@
+class HttpsFixup(object):
+    def __init__(self, app):
+        self.application = app
+    
+    def __call__(self, environ, start_response):
+        self.__fixup(environ)
+        return self.application(environ, start_response)
+    
+    
+    def __fixup(self, environ):
+        """Function to fixup the environ as needed. In order to use this
+        middleware you should set this header inside your 
+        proxy ie. nginx, apache etc.
+        """
+        proto = environ.get('HTTP_X_URL_SCHEME')
+            
+        if proto == 'https':
+            environ['wsgi.url_scheme'] = proto
+        else:
+            environ['wsgi.url_scheme'] = 'http'
+        return None