# HG changeset patch # User sylvain.thenault@logilab.fr # Date 1240938772 -7200 # Node ID 973c5f1dfad4ca2897b00ba1d954a8b6c591c5da # Parent 5cfc5cc1dd20a84162d1e5ba3d5cec742ca6797c# Parent b097057e629d98c8578e2c039f83cae7e5d62ab3 merge diff -r 5cfc5cc1dd20 -r 973c5f1dfad4 cwconfig.py --- a/cwconfig.py Tue Apr 28 19:09:37 2009 +0200 +++ b/cwconfig.py Tue Apr 28 19:12:52 2009 +0200 @@ -189,6 +189,14 @@ 'help': 'web server root url', 'group': 'main', 'inputlevel': 1, }), + ('use-request-subdomain', + {'type' : 'yn', + 'default': None, + 'help': ('if set, base-url subdomain is replaced by the request\'s ' + 'host, to help managing sites with several subdomains in a ' + 'single cubicweb instance'), + 'group': 'main', 'inputlevel': 1, + }), ('mangle-emails', {'type' : 'yn', 'default': False, diff -r 5cfc5cc1dd20 -r 973c5f1dfad4 etwist/server.py --- a/etwist/server.py Tue Apr 28 19:09:37 2009 +0200 +++ b/etwist/server.py Tue Apr 28 19:12:52 2009 +0200 @@ -10,6 +10,7 @@ import select from time import mktime from datetime import date, timedelta +from urlparse import urlsplit, urlunsplit from twisted.application import service, strports from twisted.internet import reactor, task, threads @@ -167,6 +168,12 @@ else: https = False baseurl = self.base_url + if self.config['use-request-subdomain']: + scheme, netloc, url, query, fragment = urlsplit(baseurl) + if '.' in netloc: + netloc = '.'.join(host.split('.')[:1] + netloc.split('.')[1:]) + baseurl = urlunsplit((scheme, netloc, url, query, fragment)) + self.warning('base_url is %s for this request', baseurl) req = CubicWebTwistedRequestAdapter(request, self.appli.vreg, https, baseurl) if req.authmode == 'http': # activate realm-based auth