wsgi/handler.py
changeset 8314 cfd6ab461849
parent 8312 6c2119509fac
child 8396 8d58fcf68539
equal deleted inserted replaced
8313:386b6313de28 8314:cfd6ab461849
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """WSGI request handler for cubicweb
    18 """WSGI request handler for cubicweb
    19 
    19 
    20 """
    20 """
    21 
    21 
       
    22 
       
    23 
    22 __docformat__ = "restructuredtext en"
    24 __docformat__ = "restructuredtext en"
       
    25 
       
    26 from itertools import chain, repeat, izip
    23 
    27 
    24 from cubicweb import AuthenticationError
    28 from cubicweb import AuthenticationError
    25 from cubicweb.web import Redirect, DirectResponse, StatusResponse, LogOut
    29 from cubicweb.web import Redirect, DirectResponse, StatusResponse, LogOut
    26 from cubicweb.web.application import CubicWebPublisher
    30 from cubicweb.web.application import CubicWebPublisher
    27 from cubicweb.wsgi.request import CubicWebWsgiRequest
    31 from cubicweb.wsgi.request import CubicWebWsgiRequest
    69     503: 'SERVICE UNAVAILABLE',
    73     503: 'SERVICE UNAVAILABLE',
    70     504: 'GATEWAY TIMEOUT',
    74     504: 'GATEWAY TIMEOUT',
    71     505: 'HTTP VERSION NOT SUPPORTED',
    75     505: 'HTTP VERSION NOT SUPPORTED',
    72 }
    76 }
    73 
    77 
    74 
       
    75 class WSGIResponse(object):
    78 class WSGIResponse(object):
    76     """encapsulates the wsgi response parameters
    79     """encapsulates the wsgi response parameters
    77     (code, headers and body if there is one)
    80     (code, headers and body if there is one)
    78     """
    81     """
    79     def __init__(self, code, req, body=None):
    82     def __init__(self, code, req, body=None):
    80         text = STATUS_CODE_TEXT.get(code, 'UNKNOWN STATUS CODE')
    83         text = STATUS_CODE_TEXT.get(code, 'UNKNOWN STATUS CODE')
    81         self.status =  '%s %s' % (code, text)
    84         self.status =  '%s %s' % (code, text)
    82         self.headers = [(str(k), str(v)) for k, v in req.headers_out.items()]
    85         self.headers = list(chain(*[izip(repeat(k), v)
       
    86                                     for k, v in req.headers_out.getAllRawHeaders()]))
       
    87         self.headers = [(str(k), str(v)) for k, v in self.headers]
    83         if body:
    88         if body:
    84             self.body = [body]
    89             self.body = [body]
    85         else:
    90         else:
    86             self.body = []
    91             self.body = []
    87 
    92 
   101     """
   106     """
   102 
   107 
   103     def __init__(self, config, vreg=None):
   108     def __init__(self, config, vreg=None):
   104         self.appli = CubicWebPublisher(config, vreg=vreg)
   109         self.appli = CubicWebPublisher(config, vreg=vreg)
   105         self.config = config
   110         self.config = config
   106         self.base_url = None
   111         self.base_url = config['base-url']
   107 #         self.base_url = config['base-url'] or config.default_base_url()
   112         self.https_url = config['https-url']
   108 #         assert self.base_url[-1] == '/'
       
   109 #         self.https_url = config['https-url']
       
   110 #         assert not self.https_url or self.https_url[-1] == '/'
       
   111         self.url_rewriter = self.appli.vreg['components'].select_or_none('urlrewriter')
   113         self.url_rewriter = self.appli.vreg['components'].select_or_none('urlrewriter')
   112 
   114 
   113     def _render(self, req):
   115     def _render(self, req):
   114         """this function performs the actual rendering
   116         """this function performs the actual rendering
   115         """
   117         """