Skip to content

Commit

Permalink
Message is not upgraded if Upgrade header is missing (#7895)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer authored Nov 25, 2023
1 parent 6f54953 commit fde031f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/7895.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed messages being reported as upgraded without an Upgrade header in Python parser. -- by :user:`Dreamsorcerer`
3 changes: 2 additions & 1 deletion aiohttp/http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ def parse_headers(
close_conn = True
elif v == "keep-alive":
close_conn = False
elif v == "upgrade":
# https://www.rfc-editor.org/rfc/rfc9110.html#name-101-switching-protocols
elif v == "upgrade" and headers.get(hdrs.UPGRADE):
upgrade = True

# encoding
Expand Down
9 changes: 9 additions & 0 deletions tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,15 @@ def test_conn_upgrade(parser: Any) -> None:
assert upgrade


def test_bad_upgrade(parser: Any) -> None:
"""Test not upgraded if missing Upgrade header."""
text = b"GET /test HTTP/1.1\r\nconnection: upgrade\r\n\r\n"
messages, upgrade, tail = parser.feed_data(text)
msg = messages[0][0]
assert not msg.upgrade
assert not upgrade


def test_compression_empty(parser: Any) -> None:
text = b"GET /test HTTP/1.1\r\n" b"content-encoding: \r\n\r\n"
messages, upgrade, tail = parser.feed_data(text)
Expand Down

0 comments on commit fde031f

Please sign in to comment.