Changeset 1339
- Timestamp:
- 09/06/06 18:53:46
- Files:
-
- trunk/cherrypy/lib/cptools.py (modified) (2 diffs)
- trunk/cherrypy/test/test_proxy.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/cptools.py
r1338 r1339 82 82 # Tool code # 83 83 84 def proxy(base=None, local='X-Forwarded-Host', remote='X-Forwarded-For'): 84 def proxy(base=None, local='X-Forwarded-Host', remote='X-Forwarded-For', 85 scheme='X-Forwarded-Proto'): 85 86 """Change the base URL (scheme://host[:port][/path]). 86 87 87 Useful when running a CP server behind Apache.88 For running a CP server behind Apache, lighttpd, or other HTTP server. 88 89 89 90 If you want the new request.base to include path info (not just the host), … … 100 101 request = cherrypy.request 101 102 102 if base is None: 103 port = cherrypy.local.port 104 if port == 80: 105 base = 'http://localhost' 106 else: 107 base = 'http://localhost:%s' % port 103 if scheme: 104 scheme = request.headers.get(scheme, None) 105 if not scheme: 106 scheme = request.base[:request.base.find("://")] 108 107 109 108 if local: 110 109 base = request.headers.get(local, base) 110 if not base: 111 port = cherrypy.request.local.port 112 if port == 80: 113 base = 'localhost' 114 else: 115 base = 'localhost:%s' % port 111 116 112 117 if base.find("://") == -1: 113 118 # add http:// or https:// if needed 114 base = request.base[:request.base.find("://") + 3]+ base119 base = scheme + "://" + base 115 120 116 121 request.base = base trunk/cherrypy/test/test_proxy.py
r1338 r1339 21 21 xhost._cp_config = {'tools.proxy.local': 'X-Host'} 22 22 23 def base(self): 24 return cherrypy.request.base 25 base.exposed = True 26 23 27 def newurl(self): 24 28 return ("Browse to <a href='%s'>this page</a>." … … 32 36 'environment': 'test_suite', 33 37 'tools.proxy.on': True, 34 'tools.proxy.base': ' http://www.mydomain.com',38 'tools.proxy.base': 'www.mydomain.com', 35 39 }) 36 40 … … 60 64 61 65 # Test X-Host (lighttpd; see https://trac.lighttpd.net/trac/ticket/418) 62 self.getPage("/xhost", headers=[('X-Host', ' http://www.yetanother.com')])66 self.getPage("/xhost", headers=[('X-Host', 'www.yetanother.com')]) 63 67 self.assertHeader('Location', "http://www.yetanother.com/blah") 68 69 # Test X-Forwarded-Proto (lighttpd) 70 self.getPage("/base", headers=[('X-Forwarded-Proto', 'https')]) 71 self.assertBody("https://www.mydomain.com") 64 72 65 73 # Test tree.url()

