params.pop('session_id', None)
self.params = params
+ def _handle_exception(self, exception):
+ """Called within an except block to allow converting exceptions
+ to abitrary responses. Anything returned (except None) will
+ be used as response."""
+ try:
+ return super(HttpRequest, self)._handle_exception(exception)
+ except werkzeug.exceptions.HTTPException, e:
+ return e
+
def dispatch(self):
- # TODO: refactor this correctly. This is a quick fix for pos demo.
- if request.httprequest.method == 'OPTIONS' and request.func and request.func.routing.get('cors'):
- response = werkzeug.wrappers.Response(status=200)
- response.headers.set('Access-Control-Allow-Origin', request.func.routing['cors'])
- methods = 'GET, POST'
- if request.func_request_type == 'json':
- methods = 'POST'
- elif request.func.routing.get('methods'):
- methods = ', '.join(request.func.routing['methods'])
- response.headers.set('Access-Control-Allow-Methods', methods)
- response.headers.set('Access-Control-Max-Age',60*60*24)
- response.headers.set('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
- return response
+ if request.httprequest.method == 'OPTIONS' and request.endpoint and request.endpoint.routing.get('cors'):
+ headers = {
+ 'Access-Control-Max-Age': 60 * 60 * 24,
+ 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
+ }
+ return Response(status=200, headers=headers)
r = self._call_function(**self.params)
if not r: