diff --git a/httpbin/core.py b/httpbin/core.py index 358b0f1..3c51c00 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -38,6 +38,15 @@ app = Flask(__name__) sentry = Sentry(app) +# ----------- +# Middlewares +# ----------- +@app.after_request +def set_cors_headers(response): + response.headers['Access-Control-Allow-Origin'] = '*' + return response + + # ------ # Routes # ------ diff --git a/test_httpbin.py b/test_httpbin.py index 8d7149c..7504b8d 100755 --- a/test_httpbin.py +++ b/test_httpbin.py @@ -41,6 +41,10 @@ class HttpbinTestCase(unittest.TestCase): response = self.app.post('/post', data={"file": f}) self.assertEquals(response.status_code, 200) + def test_set_cors_headers_after_request(self): + response = self.app.get('/get') + self.assertEquals(response.headers.get('Access-Control-Allow-Origin'), '*') + if __name__ == '__main__': unittest.main()