Changeset 1106
- Timestamp:
- 05/11/06 00:48:22
- Files:
-
- trunk/cherrypy/_cprequest.py (modified) (1 diff)
- trunk/cherrypy/_cptree.py (modified) (3 diffs)
- trunk/cherrypy/_cpwsgi.py (modified) (1 diff)
- trunk/cherrypy/lib/cptools.py (modified) (1 diff)
- trunk/cherrypy/lib/httptools.py (modified) (1 diff)
- trunk/cherrypy/test/test_objectmapping.py (modified) (3 diffs)
- trunk/cherrypy/test/test_tutorials.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cprequest.py
r1102 r1106 214 214 msg = "HTTP/1.1 requires a 'Host' request header." 215 215 raise cherrypy.HTTPError(400, msg) 216 self.base = "%s://%s" % (self.scheme, self.headers.get('Host', '')) 216 217 host = self.headers.get('Host', '') 218 if not host: 219 host = cherrypy.config.get('server.socket_host', '') 220 self.base = "%s://%s" % (self.scheme, host) 217 221 218 222 def get_resource(self, path): trunk/cherrypy/_cptree.py
r1105 r1106 5 5 class Application: 6 6 7 def __init__(self, root, conf=None):7 def __init__(self, root, script_name="", conf=None): 8 8 self.root = root 9 self.script_name = script_name 9 10 self.conf = {} 10 11 if conf: … … 21 22 self.apps = {} 22 23 23 def mount(self, root, script_name= None, conf=None):24 def mount(self, root, script_name="", conf=None): 24 25 """Mount a new app from a root object, script_name, and conf.""" 25 app = Application(root, conf)26 if script_name is None:27 script_name = "/"26 if script_name == "/": 27 script_name = "" 28 app = Application(root, script_name, conf) 28 29 self.apps[script_name] = app 29 30 return app … … 42 43 return None 43 44 44 while path:45 while True: 45 46 if path in self.apps: 46 47 return path 47 48 49 if path == "": 50 return None 51 48 52 # Move one node up the tree and try again. 49 if path == "/": 50 break 51 path = path[:path.rfind("/")] or "/" 52 53 return None 53 path = path[:path.rfind("/")] 54 54 55 55 def url(self, path, script_name=None): trunk/cherrypy/_cpwsgi.py
r1100 r1106 188 188 bind_addr = (conf('server.socket_host'), conf('server.socket_port')) 189 189 190 apps = [] 191 for base in cherrypy.tree.apps: 192 if base == "/": 193 base = "" 194 apps.append((base, wsgiApp)) 190 apps = [(base, wsgiApp) for base in cherrypy.tree.apps] 195 191 196 192 s = _cpwsgiserver.CherryPyWSGIServer trunk/cherrypy/lib/cptools.py
r1102 r1106 181 181 182 182 def base_url(base=None, use_x_forwarded_host=True): 183 """Change the base URL .183 """Change the base URL (scheme://host[:port]). 184 184 185 185 Useful when running a CP server behind Apache. trunk/cherrypy/lib/httptools.py
r1102 r1106 312 312 # path may be an abs_path (including "http://host.domain.tld"); 313 313 # Ignore scheme, location, and fragments (so config lookups work). 314 # [Therefore, this assumes all hosts are valid for this server.] 314 # [Therefore, this assumes all hosts are valid for this server. 315 # Note that we are also violating the RFC which says: if the host 316 # given in an abs_path, it must override any Host header.] 315 317 scheme, location, path, params, qs, frag = urlparse(path) 316 318 if path == "*": trunk/cherrypy/test/test_objectmapping.py
r1096 r1106 5 5 6 6 7 script_names = [" /", "/users/fred/blog", "/corp/blog"]7 script_names = ["", "/users/fred/blog", "/corp/blog"] 8 8 9 9 def setup_server(): … … 114 114 115 115 for url in script_names: 116 conf = {'user': url.split("/")[-2]}116 conf = {'user': (url or "/").split("/")[-2]} 117 117 cherrypy.tree.mount(Root(), url, {'/': conf}) 118 118 … … 199 199 # Test that configs don't overwrite each other from diferent apps 200 200 self.getPage("/confvalue") 201 self.assertBody( url.split("/")[-2])201 self.assertBody((url or "/").split("/")[-2]) 202 202 203 203 self.script_name = "" trunk/cherrypy/test/test_tutorials.py
r1096 r1106 22 22 else: 23 23 module = __import__(target, globals(), locals(), ['']) 24 # The above import will probably mount a new app at " /".25 app = cherrypy.tree.apps[" /"]24 # The above import will probably mount a new app at "". 25 app = cherrypy.tree.apps[""] 26 26 27 27 app.root.load_tut_module = load_tut_module

