/usr/share/pyshared/cherrypy/filters/virtualhostfilter.py is in python-cherrypy 2.3.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | """
Virtual Host Filter
From http://groups.google.com/group/cherrypy-users/browse_thread/thread/f393540fe278e54d:
For various reasons I need several domains to point to different parts of a
single website structure as well as to their own "homepage" EG
http://www.mydom1.com -> root
http://www.mydom2.com -> root/mydom2/
http://www.mydom3.com -> root/mydom3/
http://www.mydom4.com -> under construction page
but also to have http://www.mydom1.com/mydom2/ etc to be valid pages in
their own right.
"""
import cherrypy
from basefilter import BaseFilter
class VirtualHostFilter(BaseFilter):
"""Filter that changes the ObjectPath based on the Host.
Useful when running multiple sites within one CP server.
"""
def before_request_body(self):
if not cherrypy.config.get('virtual_host_filter.on', False):
return
domain = cherrypy.request.headers.get('Host', '')
if cherrypy.config.get("virtual_host_filter.use_x_forwarded_host", True):
domain = cherrypy.request.headers.get("X-Forwarded-Host", domain)
prefix = cherrypy.config.get("virtual_host_filter." + domain, "")
if prefix:
cherrypy.request.object_path = prefix + cherrypy.request.object_path
|