Robert Brewer avatar Robert Brewer committed 300a3cf

Fix for #782 (X-Forwarded-Ssl).

Comments (0)

Files changed (2)

cherrypy/lib/cptools.py

     request = cherrypy.request
     
     if scheme:
-        scheme = request.headers.get(scheme, None)
+        s = request.headers.get(scheme, None)
+        if s == 'on' and 'ssl' in scheme.lower():
+            # This handles e.g. webfaction's 'X-Forwarded-Ssl: on' header
+            scheme = 'https'
+        else:
+            # This is for lighttpd/pound/Mongrel's 'X-Forwarded-Proto: https'
+            scheme = s
     if not scheme:
         scheme = request.base[:request.base.find("://")]
     

cherrypy/test/test_proxy.py

             return cherrypy.request.base
         base.exposed = True
         
+        def ssl(self):
+            return cherrypy.request.base
+        ssl.exposed = True
+        ssl._cp_config = {'tools.proxy.scheme': 'X-Forwarded-Ssl'}
+        
         def newurl(self):
             return ("Browse to <a href='%s'>this page</a>."
                     % cherrypy.url("/this/new/page"))
         self.getPage("/base", headers=[('X-Forwarded-Proto', 'https')])
         self.assertBody("https://www.mydomain.test")
         
+        # Test X-Forwarded-Ssl (webfaction?)
+        self.getPage("/ssl", headers=[('X-Forwarded-Ssl', 'on')])
+        self.assertBody("https://www.mydomain.test")
+        
         # Test cherrypy.url()
         for sn in script_names:
             # Test the value inside requests
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.