Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CORS headers to api requests #1870

Merged
merged 2 commits into from
Oct 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions luigi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class RPCHandler(tornado.web.RequestHandler):

def initialize(self, scheduler):
self._scheduler = scheduler
self.set_header("Access-Control-Allow-Headers", "Accept, Authorization, Content-Type, Origin")
self.set_header("Access-Control-Allow-Methods", "GET, OPTIONS")
self.set_header("Access-Control-Allow-Origin", "*")

def get(self, method):
if method not in RPC_METHODS:
Expand Down
11 changes: 11 additions & 0 deletions test/server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ def test_404(self):
def test_api_404(self):
self._test_404('/api/foo')

def test_api_cors_headers(self):
response = self.fetch('/api/graph')
headers = dict(response.headers)

def _set(name):
return set(headers[name].replace(" ", "").split(","))

self.assertSetEqual(_set("Access-Control-Allow-Headers"), {"Content-Type", "Accept", "Authorization", "Origin"})
self.assertSetEqual(_set("Access-Control-Allow-Methods"), {"GET", "OPTIONS"})
self.assertEqual(headers["Access-Control-Allow-Origin"], "*")


class _ServerTest(unittest.TestCase):
"""
Expand Down