Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1339

Show
Ignore:
Timestamp:
09/06/06 18:53:46
Author:
fumanchu
Message:

New scheme arg to tools.proxy.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/lib/cptools.py

    r1338 r1339  
    8282#                                Tool code                                # 
    8383 
    84 def proxy(base=None, local='X-Forwarded-Host', remote='X-Forwarded-For'): 
     84def proxy(base=None, local='X-Forwarded-Host', remote='X-Forwarded-For', 
     85          scheme='X-Forwarded-Proto'): 
    8586    """Change the base URL (scheme://host[:port][/path]). 
    8687     
    87     Useful when running a CP server behind Apache
     88    For running a CP server behind Apache, lighttpd, or other HTTP server
    8889     
    8990    If you want the new request.base to include path info (not just the host), 
     
    100101    request = cherrypy.request 
    101102     
    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("://")] 
    108107     
    109108    if local: 
    110109        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 
    111116     
    112117    if base.find("://") == -1: 
    113118        # add http:// or https:// if needed 
    114         base = request.base[:request.base.find("://") + 3] + base 
     119        base = scheme + "://" + base 
    115120     
    116121    request.base = base 
  • trunk/cherrypy/test/test_proxy.py

    r1338 r1339  
    2121        xhost._cp_config = {'tools.proxy.local': 'X-Host'} 
    2222         
     23        def base(self): 
     24            return cherrypy.request.base 
     25        base.exposed = True 
     26         
    2327        def newurl(self): 
    2428            return ("Browse to <a href='%s'>this page</a>." 
     
    3236        'environment': 'test_suite', 
    3337        'tools.proxy.on': True, 
    34         'tools.proxy.base': 'http://www.mydomain.com', 
     38        'tools.proxy.base': 'www.mydomain.com', 
    3539        }) 
    3640 
     
    6064         
    6165        # 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')]) 
    6367        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") 
    6472         
    6573        # Test tree.url() 

Hosted by WebFaction

Log in as guest/cpguest to create tickets