Changeset 1671
- Timestamp:
- 06/17/07 15:09:58
- Files:
-
- trunk/cherrypy/__init__.py (modified) (1 diff)
- trunk/cherrypy/_cprequest.py (modified) (2 diffs)
- trunk/cherrypy/_cptree.py (modified) (5 diffs)
- trunk/cherrypy/_cpwsgi.py (modified) (2 diffs)
- trunk/cherrypy/lib/http.py (modified) (1 diff)
- trunk/cherrypy/wsgiserver/__init__.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/__init__.py
r1669 r1671 215 215 handle requests to "http://www.example.com:8080/dept/app1/", then 216 216 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 "/"). 217 220 config: a file or dict containing application config. If this contains 218 221 a [global] section, those entries will be used in the global trunk/cherrypy/_cprequest.py
r1643 r1671 298 298 script_name = "" 299 299 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 """ 301 305 302 306 path_info = "/" … … 485 489 # app root (script_name) to the handler. 486 490 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):] 488 492 489 493 self.respond(pi) trunk/cherrypy/_cptree.py
r1657 r1671 4 4 import cherrypy 5 5 from cherrypy import _cpconfig, _cplogging, _cprequest, _cpwsgi, tools 6 from cherrypy.lib import http as _http 6 7 7 8 … … 56 57 57 58 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 """ 63 74 def _get_script_name(self): 64 75 if self._script_name is None: 65 76 # 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("/") 67 78 return self._script_name 68 79 def _set_script_name(self, value): 80 if value: 81 value = value.rstrip("/") 69 82 self._script_name = value 70 83 script_name = property(fget=_get_script_name, fset=_set_script_name, … … 138 151 will handle requests to "http://www.example.com:8080/dept/app1/", 139 152 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 "/"). 140 156 config: a file or dict containing application config. 141 157 """ … … 175 191 if path is None: 176 192 try: 177 path = cherrypy.request.script_name + cherrypy.request.path_info 193 path = _http.urljoin(cherrypy.request.script_name, 194 cherrypy.request.path_info) 178 195 except AttributeError: 179 196 return None … … 193 210 # to '' (some WSGI servers always set SCRIPT_NAME to ''). 194 211 # 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', '')) 196 214 sn = self.script_name(path or "/") 197 215 if sn is None: trunk/cherrypy/_cpwsgi.py
r1670 r1671 126 126 if qs: 127 127 qs = "?" + qs 128 self.redirections.append( sn + path+ qs)128 self.redirections.append(_http.urljoin(sn, path) + qs) 129 129 130 130 # Munge environment and try again. … … 168 168 169 169 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', '')) 171 172 qs = environ.get('QUERY_STRING', '') 172 173 rproto = environ.get('SERVER_PROTOCOL') trunk/cherrypy/lib/http.py
r1664 r1671 27 27 28 28 def urljoin(*atoms): 29 """Return the given path *atoms, joined into a single URL.""" 29 30 url = "/".join(atoms) 30 31 while "//" in url: trunk/cherrypy/wsgiserver/__init__.py
r1666 r1671 12 12 return ['Hello world!\n'] 13 13 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)] 16 16 17 17 server = wsgiserver.CherryPyWSGIServer(('localhost', 8070), wsgi_apps, … … 740 740 For UNIX sockets, supply the filename as a string. 741 741 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 "/"). 743 745 numthreads: the number of worker threads to create (default 10). 744 746 server_name: the string to set for WSGI's SERVER_NAME environ entry. … … 790 792 # so that the server can call different wsgi_apps, and also 791 793 # correctly set SCRIPT_NAME. 792 self.mount_points = wsgi_app 794 self.mount_points = [(mp.rstrip("/"), app) 795 for mp, app in wsgi_app] 793 796 self.mount_points.sort() 794 797 self.mount_points.reverse()

