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

Changeset 1671

Show
Ignore:
Timestamp:
06/17/07 15:09:58
Author:
fumanchu
Message:

Trunk fix for #677 (_cpwsgi requestLine: PATH_INFO SCRIPT_NAME).

Files:

Legend:

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

    r1669 r1671  
    215215        handle requests to "http://www.example.com:8080/dept/app1/", then 
    216216        the script_name argument would be "/dept/app1". 
     217         
     218        It MUST NOT end in a slash. If the script_name refers to the root 
     219        of the URI, it MUST be an empty string (not "/"). 
    217220    config: a file or dict containing application config. If this contains 
    218221        a [global] section, those entries will be used in the global 
  • trunk/cherrypy/_cprequest.py

    r1643 r1671  
    298298    script_name = "" 
    299299    script_name__doc = """ 
    300     The 'mount point' of the application which is handling this request.""" 
     300    The 'mount point' of the application which is handling this request. 
     301     
     302    This attribute MUST NOT end in a slash. If the script_name refers to 
     303    the root of the URI, it MUST be an empty string (not "/"). 
     304    """ 
    301305     
    302306    path_info = "/" 
     
    485489            # app root (script_name) to the handler. 
    486490            self.script_name = self.app.script_name 
    487             self.path_info = pi = path[len(self.script_name.rstrip("/")):] 
     491            self.path_info = pi = path[len(self.script_name):] 
    488492             
    489493            self.respond(pi) 
  • trunk/cherrypy/_cptree.py

    r1657 r1671  
    44import cherrypy 
    55from cherrypy import _cpconfig, _cplogging, _cprequest, _cpwsgi, tools 
     6from cherrypy.lib import http as _http 
    67 
    78 
     
    5657     
    5758    script_name__doc = """ 
    58     The URI "mount point" for this app; for example, if script_name is 
    59     "/my/cool/app", then the URL "http://www.example.com/my/cool/app/page1" 
    60     might be handled by a "page1" method on the root object. If script_name 
    61     is explicitly set to None, then the script_name will be provided 
    62     for each call from request.wsgi_environ['SCRIPT_NAME'].""" 
     59    The URI "mount point" for this app. A mount point is that portion of 
     60    the URI which is constant for all URIs that are serviced by this 
     61    application; it does not include scheme, host, or proxy ("virtual host") 
     62    portions of the URI. 
     63     
     64    For example, if script_name is "/my/cool/app", then the URL 
     65    "http://www.example.com/my/cool/app/page1" might be handled by a 
     66    "page1" method on the root object. 
     67     
     68    The value of script_name MUST NOT end in a slash. If the script_name 
     69    refers to the root of the URI, it MUST be an empty string (not "/"). 
     70     
     71    If script_name is explicitly set to None, then the script_name will be 
     72    provided for each call from request.wsgi_environ['SCRIPT_NAME']. 
     73    """ 
    6374    def _get_script_name(self): 
    6475        if self._script_name is None: 
    6576            # None signals that the script name should be pulled from WSGI environ. 
    66             return cherrypy.request.wsgi_environ['SCRIPT_NAME'] 
     77            return cherrypy.request.wsgi_environ['SCRIPT_NAME'].rstrip("/") 
    6778        return self._script_name 
    6879    def _set_script_name(self, value): 
     80        if value: 
     81            value = value.rstrip("/") 
    6982        self._script_name = value 
    7083    script_name = property(fget=_get_script_name, fset=_set_script_name, 
     
    138151            will handle requests to "http://www.example.com:8080/dept/app1/", 
    139152            then the script_name argument would be "/dept/app1". 
     153             
     154            It MUST NOT end in a slash. If the script_name refers to the 
     155            root of the URI, it MUST be an empty string (not "/"). 
    140156        config: a file or dict containing application config. 
    141157        """ 
     
    175191        if path is None: 
    176192            try: 
    177                 path = cherrypy.request.script_name + cherrypy.request.path_info 
     193                path = _http.urljoin(cherrypy.request.script_name, 
     194                                     cherrypy.request.path_info) 
    178195            except AttributeError: 
    179196                return None 
     
    193210        # to '' (some WSGI servers always set SCRIPT_NAME to ''). 
    194211        # Try to look up the app using the full path. 
    195         path = environ.get('SCRIPT_NAME', '') + environ.get('PATH_INFO', '') 
     212        path = _http.urljoin(environ.get('SCRIPT_NAME', ''), 
     213                             environ.get('PATH_INFO', '')) 
    196214        sn = self.script_name(path or "/") 
    197215        if sn is None: 
  • trunk/cherrypy/_cpwsgi.py

    r1670 r1671  
    126126                if qs: 
    127127                    qs = "?" + qs 
    128                 self.redirections.append(sn + path + qs) 
     128                self.redirections.append(_http.urljoin(sn, path) + qs) 
    129129         
    130130        # Munge environment and try again. 
     
    168168             
    169169            meth = environ['REQUEST_METHOD'] 
    170             path = environ.get('SCRIPT_NAME', '') + environ.get('PATH_INFO', '') 
     170            path = _http.urljoin(environ.get('SCRIPT_NAME', ''), 
     171                                 environ.get('PATH_INFO', '')) 
    171172            qs = environ.get('QUERY_STRING', '') 
    172173            rproto = environ.get('SERVER_PROTOCOL') 
  • trunk/cherrypy/lib/http.py

    r1664 r1671  
    2727 
    2828def urljoin(*atoms): 
     29    """Return the given path *atoms, joined into a single URL.""" 
    2930    url = "/".join(atoms) 
    3031    while "//" in url: 
  • trunk/cherrypy/wsgiserver/__init__.py

    r1666 r1671  
    1212        return ['Hello world!\n'] 
    1313     
    14     # Here we set our application to the script_name '/'  
    15     wsgi_apps = [('/', my_crazy_app)] 
     14    # Here we set our application to the script_name '' 
     15    wsgi_apps = [('', my_crazy_app)] 
    1616     
    1717    server = wsgiserver.CherryPyWSGIServer(('localhost', 8070), wsgi_apps, 
     
    740740        For UNIX sockets, supply the filename as a string. 
    741741    wsgi_app: the WSGI 'application callable'; multiple WSGI applications 
    742         may be passed as (script_name, callable) pairs. 
     742        may be passed as (script_name, callable) pairs. Script_name values 
     743        should not end in a slash. If the script_name refers to the root 
     744        of the URI, it should be an empty string (not "/"). 
    743745    numthreads: the number of worker threads to create (default 10). 
    744746    server_name: the string to set for WSGI's SERVER_NAME environ entry. 
     
    790792            # so that the server can call different wsgi_apps, and also 
    791793            # correctly set SCRIPT_NAME. 
    792             self.mount_points = wsgi_app 
     794            self.mount_points = [(mp.rstrip("/"), app) 
     795                                 for mp, app in wsgi_app] 
    793796        self.mount_points.sort() 
    794797        self.mount_points.reverse() 

Hosted by WebFaction

Log in as guest/cpguest to create tickets