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

Message is not upgraded if Upgrade header is missing #7895

Merged
merged 6 commits into from
Nov 25, 2023
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/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):
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
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
Loading