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
(cherry picked from commit af2bb1e)
  • Loading branch information
bdraco committed Oct 31, 2023
1 parent d179f09 commit b940aeb
Show file tree
Hide file tree
Showing 3 changed files with 10 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 @@ -974,7 +974,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
9 changes: 8 additions & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from yarl import URL

from aiohttp import helpers
from aiohttp.helpers import parse_http_date
from aiohttp.helpers import method_must_be_empty_body, parse_http_date

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

Expand Down Expand Up @@ -909,3 +909,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 b940aeb

Please sign in to comment.