OPSI.web2.vhost module

I am a virtual hosts implementation.

class OPSI.web2.vhost.VHostURIRewrite(uri, resource)

Bases: object

I do request mangling to insure that children know what host they are being accessed from behind mod_proxy.

Usage:

  • Twisted:

    root = MyResource()
    vur = vhost.VHostURIRewrite(uri='http://hostname:port/path', resource=root)
    server.Site(vur)
    
  • Apache:

    <VirtualHost hostname:port>
        ProxyPass /path/ http://localhost:8080/
        Servername hostname
    </VirtualHost>
    

If the trailing / is ommitted in the second argument to ProxyPass VHostURIRewrite will return a 404 response code.

uri must be a fully specified uri complete with scheme://hostname/path/

locateChild(req, segments)
renderHTTP(req)
class OPSI.web2.vhost.AutoVHostURIRewrite(resource, sendsRealHost=False)

Bases: object

I do request mangling to insure that children know what host they are being accessed from behind apache2.

Usage:

  • Twisted:

    root = MyResource()
    vur = vhost.AutoVHostURIRewrite(root)
    
  • Apache2:

    <Location /whatever/>
      ProxyPass http://localhost:8538/
      RequestHeader set X-App-Location /whatever/
    </Location>
    

If the trailing / is ommitted in the second argument to ProxyPass VHostURIRewrite will return a 404 response code.

If proxying HTTPS, add this to the Apache config:

RequestHeader set X-App-Scheme https
locateChild(req, segments)
renderHTTP(req)
class OPSI.web2.vhost.NameVirtualHost(default=None)

Bases: OPSI.web2.resource.Resource

Resource in charge of dispatching requests to other resources based on the value of the HTTP ‘Host’ header.

@param supportNested: If True domain segments will be chopped off until the
TLD is reached or a matching virtual host is found. (In which case the child resource can do its own more specific virtual host lookup.)
addHost(name, resrc)

Add a host to this virtual host. - The Fun Stuff(TM)

This associates a host named ‘name’ with a resource ‘resrc’:

nvh.addHost('nevow.com', nevowDirectory)
nvh.addHost('divmod.org', divmodDirectory)
nvh.addHost('twistedmatrix.com', twistedMatrixDirectory)

I told you that was fun.

@param name: The FQDN to be matched to the ‘Host’ header. @type name: C{str}

@param resrc: The L{OPSI.web2.iweb.IResource} to be served as the
given hostname.

@type resource: L{OPSI.web2.iweb.IResource}

locateChild(req, segments)

It’s a NameVirtualHost, do you know where your children are?

This uses locateChild magic so you don’t have to mutate the request.

removeHost(name)

Remove the given host. @param name: The FQDN to remove. @type name: C{str}

supportNested = True