From ff0e5318f65d9cf05812d2edd4b0e0d2ff6d2268 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 30 Jan 2014 16:14:25 +0100 Subject: [PATCH] [ADD] Support cors for pos demo bzr revid: fme@openerp.com-20140130151425-tkcv5cvx04og0neu --- openerp/http.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/openerp/http.py b/openerp/http.py index 717582e2ec5..0f3e7023345 100644 --- a/openerp/http.py +++ b/openerp/http.py @@ -410,6 +410,19 @@ class HttpRequest(WebRequest): self.params = params def dispatch(self): + # TODO: refactor this correctly. This is a quick fix for pos demo. + if request.httprequest.method == 'OPTIONS' and request.func.cors: + response = werkzeug.wrappers.Response(status=200) + response.headers.set('Access-Control-Allow-Origin', request.func.cors) + methods = 'GET, POST' + if request.func_request_type == 'json': + methods = 'POST' + elif request.func.methods: + methods = ', '.join(request.func.methods) + response.headers.set('Access-Control-Allow-Methods', methods) + response.headers.set('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept') + return response + r = self._call_function(**self.params) if not r: r = werkzeug.wrappers.Response(status=204) # no content