etwist/server.py
branchtls-sprint
changeset 1520 b097057e629d
parent 1420 25c13e5b12bd
child 1542 2965fcfaeca1
equal deleted inserted replaced
1490:6b024694d493 1520:b097057e629d
     8 
     8 
     9 import sys
     9 import sys
    10 import select
    10 import select
    11 from time import mktime
    11 from time import mktime
    12 from datetime import date, timedelta
    12 from datetime import date, timedelta
       
    13 from urlparse import urlsplit, urlunsplit
    13 
    14 
    14 from twisted.application import service, strports
    15 from twisted.application import service, strports
    15 from twisted.internet import reactor, task, threads
    16 from twisted.internet import reactor, task, threads
    16 from twisted.internet.defer import maybeDeferred
    17 from twisted.internet.defer import maybeDeferred
    17 from twisted.web2 import channel, http, server, iweb
    18 from twisted.web2 import channel, http, server, iweb
   165             https = True
   166             https = True
   166             baseurl = self.https_url or self.base_url
   167             baseurl = self.https_url or self.base_url
   167         else:
   168         else:
   168             https = False
   169             https = False
   169             baseurl = self.base_url
   170             baseurl = self.base_url
       
   171         if self.config['use-request-subdomain']:
       
   172             scheme, netloc, url, query, fragment = urlsplit(baseurl)
       
   173             if '.' in netloc:
       
   174                 netloc = '.'.join(host.split('.')[:1] + netloc.split('.')[1:])
       
   175             baseurl = urlunsplit((scheme, netloc, url, query, fragment))
       
   176             self.warning('base_url is %s for this request', baseurl)
   170         req = CubicWebTwistedRequestAdapter(request, self.appli.vreg, https, baseurl)
   177         req = CubicWebTwistedRequestAdapter(request, self.appli.vreg, https, baseurl)
   171         if req.authmode == 'http':
   178         if req.authmode == 'http':
   172             # activate realm-based auth
   179             # activate realm-based auth
   173             realm = self.config['realm']
   180             realm = self.config['realm']
   174             req.set_header('WWW-Authenticate', [('Basic', {'realm' : realm })], raw=False)
   181             req.set_header('WWW-Authenticate', [('Basic', {'realm' : realm })], raw=False)