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 2 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
2 changes: 1 addition & 1 deletion aiohttp/http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def parse_headers(
close_conn = True
elif v == "keep-alive":
close_conn = False
elif v == "upgrade":
elif v == "upgrade" and headers.get(hdrs.UPGRADE):
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
upgrade = True

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


def test_bad_upgrade(parser: Any) -> None:
"""Test not upgraded if missing Upgrade header."""

Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
text = b"GET /test HTTP/1.1\r\n" b"connection: upgrade\r\n\r\n"
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
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