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

Make JSON media type matching case insensitive #6181

Merged
merged 1 commit into from
Oct 31, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/6181.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make JSON media type matching case insensitive per RFC 2045.
2 changes: 1 addition & 1 deletion aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def iscoroutinefunction(func: Any) -> bool:
return asyncio.iscoroutinefunction(func)


json_re = re.compile(r"(?:application/|[\w.-]+/[\w.+-]+?\+)json")
json_re = re.compile(r"(?:application/|[\w.-]+/[\w.+-]+?\+)json", re.IGNORECASE)


class BasicAuth(namedtuple("BasicAuth", ["login", "password", "encoding"])):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,15 @@ def test_is_expected_content_type_non_application_json_private_suffix():
)


def test_is_expected_content_type_json_non_lowercase():
"""Per RFC 2045, media type matching is case insensitive."""
expected_ct = "application/json"
response_ct = "Application/JSON"
assert is_expected_content_type(
response_content_type=response_ct, expected_content_type=expected_ct
)


def test_is_expected_content_type_non_json_match_exact():
expected_ct = "text/javascript"
response_ct = "text/javascript"
Expand Down