Skip to content

Commit

Permalink
Merge pull request #338 from mozilla-services/fix-max-age-if-undefined
Browse files Browse the repository at this point in the history
Fix Access-Control-Max-Age value if undefined on service
  • Loading branch information
almet committed Sep 28, 2015
2 parents f94dd6c + 035387e commit c71b5c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cornice/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,15 @@ def cors_support_credentials_for(self, method=None):
return False

def cors_max_age_for(self, method=None):
max_age = None
for meth, view, args in self.definitions:
if method and meth.upper() == method.upper():
return args.get('cors_max_age', False)
max_age = args.get('cors_max_age', None)
break

return getattr(self, 'cors_max_age', None)
if max_age is None:
max_age = getattr(self, 'cors_max_age', None)
return max_age


def decorate_view(view, args, method):
Expand Down
5 changes: 5 additions & 0 deletions cornice/tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ def test_method_takes_precendence_for_credential_support(self):
foo.add_view('GET', _stub, cors_credentials=False)
self.assertFalse(foo.cors_support_credentials_for('GET'))

def test_max_age_is_none_if_undefined(self):
foo = Service(name='foo', path='/foo')
foo.add_view('POST', _stub)
self.assertIsNone(foo.cors_max_age_for('POST'))

def test_max_age_can_be_defined(self):
foo = Service(name='foo', path='/foo', cors_max_age=42)
foo.add_view('POST', _stub)
Expand Down

0 comments on commit c71b5c4

Please sign in to comment.