[ADD] Support cors for pos demo
bzr revid: fme@openerp.com-20140130151425-tkcv5cvx04og0neu
This commit is contained in:
parent
3a8291d8ed
commit
ff0e5318f6
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue