Skip to content

Commit

Permalink
Fix CONNECT always being treated as having an empty body (aio-libs#7772)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Oct 31, 2023
1 parent 015f14c commit af2bb1e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/7772.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix CONNECT always being treated as having an empty body
2 changes: 1 addition & 1 deletion aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ def method_must_be_empty_body(method: str) -> bool:
"""Check if a method must return an empty body."""
# https://datatracker.ietf.org/doc/html/rfc9112#section-6.3-2.1
# https://datatracker.ietf.org/doc/html/rfc9112#section-6.3-2.2
return method.upper() in (hdrs.METH_CONNECT, hdrs.METH_HEAD)
return method.upper() == hdrs.METH_HEAD


def status_code_must_be_empty_body(code: int) -> bool:
Expand Down
13 changes: 12 additions & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
from yarl import URL

from aiohttp import helpers
from aiohttp.helpers import is_expected_content_type, parse_http_date
from aiohttp.helpers import (
is_expected_content_type,
method_must_be_empty_body,
parse_http_date,
)

IS_PYPY = platform.python_implementation() == "PyPy"

Expand Down Expand Up @@ -1071,3 +1075,10 @@ def test_read_basicauth_from_empty_netrc():
LookupError, match="No entry for example.com found in the `.netrc` file."
):
helpers.basicauth_from_netrc(netrc_obj, "example.com")


def test_method_must_be_empty_body():
"""Test that HEAD is the only method that unequivocally must have an empty body."""
assert method_must_be_empty_body("HEAD") is True
# CONNECT is only empty on a successful response
assert method_must_be_empty_body("CONNECT") is False

0 comments on commit af2bb1e

Please sign in to comment.