1 """WSGI request handler for cubicweb |
1 """WSGI request handler for cubicweb |
2 |
2 |
3 :organization: Logilab |
3 :organization: Logilab |
4 :copyright: 2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
4 :copyright: 2008-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 """ |
6 """ |
7 |
7 |
8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
9 |
9 |
98 # assert not self.https_url or self.https_url[-1] == '/' |
98 # assert not self.https_url or self.https_url[-1] == '/' |
99 try: |
99 try: |
100 self.url_rewriter = self.appli.vreg.select_component('urlrewriter') |
100 self.url_rewriter = self.appli.vreg.select_component('urlrewriter') |
101 except ObjectNotFound: |
101 except ObjectNotFound: |
102 self.url_rewriter = None |
102 self.url_rewriter = None |
103 |
103 |
104 def _render(self, req): |
104 def _render(self, req): |
105 """this function performs the actual rendering |
105 """this function performs the actual rendering |
106 XXX missing: https handling, url rewriting, cache management, |
106 XXX missing: https handling, url rewriting, cache management, |
107 authentication |
107 authentication |
108 """ |
108 """ |
154 # no result, something went wrong... |
154 # no result, something went wrong... |
155 self.error('no data (%s)', req) |
155 self.error('no data (%s)', req) |
156 # 500 Internal server error |
156 # 500 Internal server error |
157 return self.redirect(req, req.build_url('error')) |
157 return self.redirect(req, req.build_url('error')) |
158 return WSGIResponse(200, req, result) |
158 return WSGIResponse(200, req, result) |
159 |
159 |
160 |
160 |
161 def __call__(self, environ, start_response): |
161 def __call__(self, environ, start_response): |
162 """WSGI protocol entry point""" |
162 """WSGI protocol entry point""" |
163 req = CubicWebWsgiRequest(environ, self.appli.vreg, self.base_url) |
163 req = CubicWebWsgiRequest(environ, self.appli.vreg, self.base_url) |
164 response = self._render(req) |
164 response = self._render(req) |
165 start_response(response.status, response.headers) |
165 start_response(response.status, response.headers) |
168 def redirect(self, req, location): |
168 def redirect(self, req, location): |
169 """convenience function which builds a redirect WSGIResponse""" |
169 """convenience function which builds a redirect WSGIResponse""" |
170 self.debug('redirecting to %s', location) |
170 self.debug('redirecting to %s', location) |
171 req.set_header('location', str(location)) |
171 req.set_header('location', str(location)) |
172 return WSGIResponse(303, req) |
172 return WSGIResponse(303, req) |
173 |
173 |
174 def request_auth(self, req, loggedout=False): |
174 def request_auth(self, req, loggedout=False): |
175 """returns the appropriate WSGIResponse to require the user to log in |
175 """returns the appropriate WSGIResponse to require the user to log in |
176 """ |
176 """ |
177 # if self.https_url and req.base_url() != self.https_url: |
177 # if self.https_url and req.base_url() != self.https_url: |
178 # return self.redirect(self.https_url + 'login') |
178 # return self.redirect(self.https_url + 'login') |