Adding CORS support for all requests

This commit is contained in:
Rodrigo Chacon
2013-01-10 03:56:24 -02:00
committed by Rodrigo Chacon
parent 98ed28b547
commit 61bed33f24
2 changed files with 13 additions and 0 deletions
+9
View File
@@ -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
# ------
+4
View File
@@ -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()