Commit dce48e58 authored by Lukáš Lalinský's avatar Lukáš Lalinský

Add CORS headers

parent 144c48ba
Pipeline #20403 failed with stages
in 1 minute and 49 seconds
......@@ -103,6 +103,15 @@ def replace_double_slashes(app):
return wrapped_app
def add_cors_headers(app):
def wrapped_app(environ, start_response):
def start_response_with_cors_headers(status, headers, exc_info=None):
headers.append(('Access-Control-Allow-Origin', '*'))
return start_response(status, headers, exc_info)
return app(environ, start_response_with_cors_headers)
return wrapped_app
def make_application(config_path):
"""Construct a WSGI application for the AcoustID server
......@@ -114,4 +123,5 @@ def make_application(config_path):
app = ProxyFix(app)
app = SentryWsgiMiddleware(app)
app = replace_double_slashes(app)
app = add_cors_headers(app)
return server, app
......@@ -5,7 +5,7 @@ from nose.tools import assert_equals
import gzip
import wsgiref.util
from cStringIO import StringIO
from acoustid.server import GzipRequestMiddleware, replace_double_slashes
from acoustid.server import GzipRequestMiddleware, replace_double_slashes, add_cors_headers
def test_gzip_request_middleware():
......@@ -34,3 +34,17 @@ def test_replace_double_slashes():
wsgiref.util.setup_testing_defaults(environ)
mw = replace_double_slashes(app)
mw(environ, None)
def test_add_cors_headers():
def app(environ, start_response):
start_response(200, [])
gzcontent = StringIO()
environ = {}
wsgiref.util.setup_testing_defaults(environ)
mw = add_cors_headers(app)
def start_response(status, headers, exc_info=None):
h = dict(headers)
print(h)
assert_equals(h['Access-Control-Allow-Origin'], '*')
mw(environ, start_response)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment