mirror of
https://github.com/kennethreitz/httpbin.git
synced 2026-06-05 23:00:18 +00:00
Adding CORS support for all requests
This commit is contained in:
committed by
Rodrigo Chacon
parent
98ed28b547
commit
61bed33f24
@@ -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
|
||||
# ------
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user