Skip to content

Commit

Permalink
Make JSON media type matching case insensitive (#6181)
Browse files Browse the repository at this point in the history
Per RFC 2045, section 2 and appendix A.
  • Loading branch information
scop committed Oct 31, 2021
1 parent 9c7f3d3 commit 15adfbc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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

0 comments on commit 15adfbc

Please sign in to comment.