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

Makes string matching case insensitive #188

Merged
merged 1 commit into from Sep 8, 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
5 changes: 4 additions & 1 deletion flask_cors/core.py
Expand Up @@ -270,7 +270,10 @@ def try_match(request_origin, maybe_regex):
elif probably_regex(maybe_regex):
return re.match(maybe_regex, request_origin, flags=re.IGNORECASE)
else:
return request_origin == maybe_regex
try:
return request_origin.lower() == maybe_regex.lower()
except AttributeError:
return request_origin == maybe_regex


def get_cors_options(appInstance, *dicts):
Expand Down
12 changes: 12 additions & 0 deletions tests/decorator/test_allow_headers.py
Expand Up @@ -58,6 +58,18 @@ def test_allow_headers_with_request_headers(self):
self.assertEqual(resp.headers.get(ACL_ALLOW_HEADERS),
'X-Example-Header-A')

def test_allow_headers_with_request_headers_case_insensitive(self):
'''
HTTP headers are case insensitive. We should respect that
and match regardless of case, returning the casing sent by
the client
'''
resp = self.preflight('/test_allow_headers',
origin='www.example.com',
cors_request_headers=['X-Example-header-a'])
self.assertEqual(resp.headers.get(ACL_ALLOW_HEADERS),
'X-Example-header-a')

def test_allow_headers_with_unmatched_request_headers(self):
'''
If every element in the Access-Control-Request-Headers is not an
Expand Down