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

root/branches/cherrypy-2.x/cherrypy/filters/virtualhostfilter.py

Revision 1241 (checked in by fumanchu, 2 years ago)

Fix for #543 (virtualhostfilter.py generates URIs with a double slash).

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

Hosted by WebFaction

Log in as guest/cpguest to create tickets