web/application.py
changeset 10744 c5dc40988e6e
parent 10740 59e89db3a67d
child 10777 eabacd3c6f16
equal deleted inserted replaced
10743:1e1c560cc610 10744:c5dc40988e6e
    23 from time import clock, time
    23 from time import clock, time
    24 from contextlib import contextmanager
    24 from contextlib import contextmanager
    25 from warnings import warn
    25 from warnings import warn
    26 import json
    26 import json
    27 
    27 
    28 from six import text_type
    28 from six import text_type, binary_type
    29 from six.moves import http_client
    29 from six.moves import http_client
    30 
    30 
    31 from logilab.common.deprecation import deprecated
    31 from logilab.common.deprecation import deprecated
    32 
    32 
    33 from rql import BadRQLQuery
    33 from rql import BadRQLQuery
   255             req, path = path, req
   255             req, path = path, req
   256         if req.authmode == 'http':
   256         if req.authmode == 'http':
   257             # activate realm-based auth
   257             # activate realm-based auth
   258             realm = self.vreg.config['realm']
   258             realm = self.vreg.config['realm']
   259             req.set_header('WWW-Authenticate', [('Basic', {'realm' : realm })], raw=False)
   259             req.set_header('WWW-Authenticate', [('Basic', {'realm' : realm })], raw=False)
   260         content = ''
   260         content = b''
   261         try:
   261         try:
   262             try:
   262             try:
   263                 session = self.get_session(req)
   263                 session = self.get_session(req)
   264                 from  cubicweb import repoapi
   264                 from  cubicweb import repoapi
   265                 cnx = repoapi.Connection(session)
   265                 cnx = repoapi.Connection(session)
   326                 # If previous error handling already generated a custom content
   326                 # If previous error handling already generated a custom content
   327                 # do not overwrite it. This is used by LogOut Except
   327                 # do not overwrite it. This is used by LogOut Except
   328                 # XXX ensure we don't actually serve content
   328                 # XXX ensure we don't actually serve content
   329                 if not content:
   329                 if not content:
   330                     content = self.need_login_content(req)
   330                     content = self.need_login_content(req)
       
   331         assert isinstance(content, binary_type)
   331         return content
   332         return content
   332 
   333 
   333 
   334 
   334     def core_handle(self, req, path):
   335     def core_handle(self, req, path):
   335         """method called by the main publisher to process <path>
   336         """method called by the main publisher to process <path>
   367                 req.update_search_state()
   368                 req.update_search_state()
   368                 result = controller.publish(rset=rset)
   369                 result = controller.publish(rset=rset)
   369             except cors.CORSPreflight:
   370             except cors.CORSPreflight:
   370                 # Return directly an empty 200
   371                 # Return directly an empty 200
   371                 req.status_out = 200
   372                 req.status_out = 200
   372                 result = ''
   373                 result = b''
   373             except StatusResponse as ex:
   374             except StatusResponse as ex:
   374                 warn('[3.16] StatusResponse is deprecated use req.status_out',
   375                 warn('[3.16] StatusResponse is deprecated use req.status_out',
   375                      DeprecationWarning, stacklevel=2)
   376                      DeprecationWarning, stacklevel=2)
   376                 result = ex.content
   377                 result = ex.content
   377                 req.status_out = ex.status
   378                 req.status_out = ex.status