etwist/server.py
changeset 4914 dcb055f32d9b
parent 4772 ae1b2a0c8e86
parent 4911 898c35be5873
child 4960 26b2468a1e73
equal deleted inserted replaced
4913:083b4d454192 4914:dcb055f32d9b
    97     addSlash = False
    97     addSlash = False
    98 
    98 
    99     def __init__(self, config, debug=None):
    99     def __init__(self, config, debug=None):
   100         self.debugmode = debug
   100         self.debugmode = debug
   101         self.config = config
   101         self.config = config
   102         self.base_url = config['base-url'] or config.default_base_url()
       
   103         if self.base_url[-1] != '/':
       
   104             self.base_url += '/'
       
   105         self.https_url = config['https-url']
       
   106         if self.https_url and self.https_url[-1] != '/':
       
   107             self.https_url += '/'
       
   108         # instantiate publisher here and not in init_publisher to get some
   102         # instantiate publisher here and not in init_publisher to get some
   109         # checks done before daemonization (eg versions consistency)
   103         # checks done before daemonization (eg versions consistency)
   110         self.appli = CubicWebPublisher(config, debug=self.debugmode)
   104         self.appli = CubicWebPublisher(config, debug=self.debugmode)
       
   105         self.base_url = config['base-url']
       
   106         self.https_url = config['https-url']
   111         self.versioned_datadir = 'data%s' % config.instance_md5_version()
   107         self.versioned_datadir = 'data%s' % config.instance_md5_version()
   112 
   108 
   113     def init_publisher(self):
   109     def init_publisher(self):
   114         config = self.config
   110         config = self.config
   115         # when we have an in-memory repository, clean unused sessions every XX
   111         # when we have an in-memory repository, clean unused sessions every XX
   248             result = self.appli.notfound_content(req)
   244             result = self.appli.notfound_content(req)
   249             return http.Response(stream=result, code=responsecode.NOT_FOUND,
   245             return http.Response(stream=result, code=responsecode.NOT_FOUND,
   250                                  headers=req.headers_out or None)
   246                                  headers=req.headers_out or None)
   251         except ExplicitLogin:  # must be before AuthenticationError
   247         except ExplicitLogin:  # must be before AuthenticationError
   252             return self.request_auth(req)
   248             return self.request_auth(req)
   253         except AuthenticationError:
   249         except AuthenticationError, ex:
   254             if self.config['auth-mode'] == 'cookie':
   250             if self.config['auth-mode'] == 'cookie' and getattr(ex, 'url', None):
   255                 # in cookie mode redirecting to the index view is enough :
   251                 return self.redirect(req, ex.url)
   256                 # either anonymous connection is allowed and the page will
   252             # in http we have to request auth to flush current http auth
   257                 # be displayed or we'll be redirected to the login form
   253             # information
   258                 msg = req._('you have been logged out')
   254             return self.request_auth(req, loggedout=True)
   259                 if req.https:
       
   260                     req._base_url =  self.base_url
       
   261                     req.https = False
       
   262                 url = req.build_url('view', vid='index', __message=msg)
       
   263                 return self.redirect(req, url)
       
   264             else:
       
   265                 # in http we have to request auth to flush current http auth
       
   266                 # information
       
   267                 return self.request_auth(req, loggedout=True)
       
   268         except Redirect, ex:
   255         except Redirect, ex:
   269             return self.redirect(req, ex.location)
   256             return self.redirect(req, ex.location)
   270         # request may be referenced by "onetime callback", so clear its entity
   257         # request may be referenced by "onetime callback", so clear its entity
   271         # cache to avoid memory usage
   258         # cache to avoid memory usage
   272         req.drop_entity_cache()
   259         req.drop_entity_cache()