Skip to content

Commit

Permalink
Merge pull request #301 from mozilla-services/fix-duplicated-cors-hea…
Browse files Browse the repository at this point in the history
…ders

Fix duplicated CORS exposed headers
  • Loading branch information
leplatrem committed Jun 12, 2015
2 parents aeee7b2 + 8fe6309 commit 28667f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cornice/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def cors_supported_headers_for(self, method=None):
exposed_headers = args.get('cors_headers', ())
if method is not None:
if meth.upper() == method.upper():
return exposed_headers
return set(exposed_headers)
else:
headers |= set(exposed_headers)
return headers
Expand Down
10 changes: 10 additions & 0 deletions cornice/tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,16 @@ def test_cors_headers_for_method(self):
get_headers = service.cors_supported_headers_for(method='GET')
self.assertNotIn('X-Header-Barbaz', get_headers)

def test_cors_headers_for_method_are_deduplicated(self):
# defining headers in the view should work.
service = Service('coconuts', '/migrate')
service.cors_headers = ('X-Header-Foobar',)
service.add_view('GET', _stub,
cors_headers=('X-Header-Foobar', 'X-Header-Barbaz'))
get_headers = service.cors_supported_headers_for(method='GET')
expected = set(['X-Header-Foobar', 'X-Header-Barbaz'])
self.assertEqual(expected, get_headers)

def test_cors_supported_methods(self):
foo = Service(name='foo', path='/foo', cors_enabled=True)
foo.add_view('GET', _stub)
Expand Down

0 comments on commit 28667f2

Please sign in to comment.