Added CORS headers to API json_response
authorJoar Wandborg <git@wandborg.com>
Sat, 15 Sep 2012 20:18:49 +0000 (22:18 +0200)
committerJoar Wandborg <git@wandborg.com>
Sat, 15 Sep 2012 20:18:49 +0000 (22:18 +0200)
mediagoblin/plugins/api/tools.py

index e3b15b2332bec88b825849d040c181699b61a9e8..5488e5159b002158ea18a2f4fd870cf461e88c90 100644 (file)
@@ -63,6 +63,11 @@ def json_response(serializable, *args, **kw):
     '''
     response = Response(json.dumps(serializable), *args, **kw)
     response.headers['Content-Type'] = 'application/json'
+    cors_headers = {
+            'Access-Control-Allow-Origin': '*',
+            'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
+            'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With'}
+    response.headers.update(cors_headers)
     return response