merge tls-sprint
authorsylvain.thenault@logilab.fr
Tue, 28 Apr 2009 19:12:52 +0200
branchtls-sprint
changeset 1521 973c5f1dfad4
parent 1519 5cfc5cc1dd20 (current diff)
parent 1520 b097057e629d (diff)
child 1522 47b2ffbee760
merge
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,
--- 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