summaryrefslogtreecommitdiff
path: root/cherrypy/lib/cptools.py
diff options
context:
space:
mode:
authorRobert Brewer <fumanchu@aminus.org>2006-05-10 06:11:38 +0000
committerRobert Brewer <fumanchu@aminus.org>2006-05-10 06:11:38 +0000
commit0185346d79ff89e7c092ad3b39448d755ba872c6 (patch)
treec92158a8d9d076429ea2bbf4ee628bf103607da8 /cherrypy/lib/cptools.py
parent678e56cf1571a53cf3352e12f15acea7b414389e (diff)
downloadcherrypy-git-0185346d79ff89e7c092ad3b39448d755ba872c6.tar.gz
Dispatch and config lookup now happens as early as possible, once per request (unless InternalRedirect is raised). Also moved the logging code out of {{{_cputil}}} and into {{{__init__}}}. xmlrpc still needs fixed so it doesn't re-write path_info.
Diffstat (limited to 'cherrypy/lib/cptools.py')
-rw-r--r--cherrypy/lib/cptools.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/cherrypy/lib/cptools.py b/cherrypy/lib/cptools.py
index c9e3c39d..e67bfac6 100644
--- a/cherrypy/lib/cptools.py
+++ b/cherrypy/lib/cptools.py
@@ -6,6 +6,7 @@ import sys
import time
import cherrypy
+import httptools
def decorate(func, decorator):
@@ -287,7 +288,7 @@ def session_auth(check_login_and_password=None, not_logged_in=None,
return False
def virtual_host(use_x_forwarded_host=True, **domains):
- """Change the path_info based on the Host.
+ """Redirect internally based on the Host header.
Useful when running multiple sites within one CP server.
@@ -304,14 +305,16 @@ def virtual_host(use_x_forwarded_host=True, **domains):
but also to have http://www.mydom1.com/mydom2/ etc to be valid pages in
their own right.
"""
+ if hasattr(cherrypy.request, "virtual_prefix"):
+ return
domain = cherrypy.request.headers.get('Host', '')
if use_x_forwarded_host:
domain = cherrypy.request.headers.get("X-Forwarded-Host", domain)
- prefix = domains.get(domain, "")
+ cherrypy.request.virtual_prefix = prefix = domains.get(domain, "")
if prefix:
- cherrypy.request.path_info = prefix + "/" + cherrypy.request.path_info
+ raise cherrypy.InternalRedirect(httptools.urljoin(prefix, cherrypy.request.path_info))
def log_traceback():
"""Write the last error's traceback to the cherrypy error log."""