Package cherrypy :: Module _cpwsgi :: Class VirtualHost
[hide private]
[frames] | no frames]

Class VirtualHost

source code

object --+
         |
        VirtualHost

Select a different WSGI application based on the Host header.

This can be useful when running multiple sites within one CP server.
It allows several domains to point to different applications. For example:

    root = Root()
    RootApp = cherrypy.Application(root)
    Domain2App = cherrypy.Application(root)
    SecureApp = cherrypy.Application(Secure())
    
    vhost = cherrypy._cpwsgi.VirtualHost(RootApp,
        domains={'www.domain2.example': Domain2App,
                 'www.domain2.example:443': SecureApp,
                 })
    
    cherrypy.tree.graft(vhost)

default: required. The default WSGI application.

use_x_forwarded_host: if True (the default), any "X-Forwarded-Host"
    request header will be used instead of the "Host" header. This
    is commonly added by HTTP servers (such as Apache) when proxying.

domains: a dict of {host header value: application} pairs.
    The incoming "Host" request header is looked up in this dict,
    and, if a match is found, the corresponding WSGI application
    will be called instead of the default. Note that you often need
    separate entries for "example.com" and "www.example.com".
    In addition, "Host" headers may contain the port number.

Instance Methods [hide private]
 
__init__(self, default, domains=None, use_x_forwarded_host=True)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
__call__(self, environ, start_response) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, default, domains=None, use_x_forwarded_host=True)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)