Robert Brewer committed 19d41e0

X-Forwarded-For should overwrite remote.ip, not

Comments (0)

Files changed (3)

     you must explicitly set base to the full base path, and ALSO set 'local'
     to '', so that the X-Forwarded-Host request header (which never includes
     path info) does not override it.
+    cherrypy.request.remote.ip (the IP address of the client) will be
+    rewritten if the header specified by the 'remote' arg is valid.
+    By default, 'remote' is set to 'X-Forwarded-For'. If you do not
+    want to rewrite remote.ip, set the 'remote' arg to an empty string.
     request = cherrypy.request
             if remote == 'X-Forwarded-For':
                 # See
                 xff = xff.split(',')[-1].strip()
-   = xff
+            request.remote.ip = xff
 def response_headers(headers=None):
 def decode(encoding=None, default_encoding='utf-8'):
-    """Decode cherrypy.request.params ."""
+    """Decode cherrypy.request.params."""
     if not encoding:
         ct = cherrypy.request.headers.elements("Content-Type")
         if ct:


             raise cherrypy.HTTPRedirect('dummy') = True
-        def remotehost(self):
-            return
- = True
+        def remoteip(self):
+            return cherrypy.request.remote.ip
+ = True
         def xhost(self):
             raise cherrypy.HTTPRedirect('blah')
         self.assertHeader('Location', "")
         # Test X-Forwarded-For (Apache2)
-        self.getPage("/remotehost",
+        self.getPage("/remoteip",
                      headers=[('X-Forwarded-For', '')])
-        self.getPage("/remotehost",
+        self.getPage("/remoteip",
                      headers=[('X-Forwarded-For', ',')])
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
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.