Skip to content

Commit

Permalink
sync helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Oct 30, 2023
1 parent 998a875 commit f459e8e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,17 +1067,18 @@ def parse_http_date(date_str: Optional[str]) -> Optional[datetime.datetime]:

def must_be_empty_body(method: str, code: int) -> bool:
"""Check if a request must return an empty body."""
# https://datatracker.ietf.org/doc/html/rfc9112#section-6.3
return status_code_must_be_empty_body(code) or method_must_be_empty_body(method)


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)
# https://datatracker.ietf.org/doc/html/rfc9112#section-6.3
return method in (hdrs.METH_CONNECT, hdrs.METH_HEAD)


def status_code_must_be_empty_body(code: int) -> bool:
"""Check if a status code must return an empty body."""
# https://datatracker.ietf.org/doc/html/rfc9112#section-6.3-2.1
return code in {204, 304} or 100 <= code < 200
# 204, 304, 1xx should not have a body per
# https://datatracker.ietf.org/doc/html/rfc9112#section-6.3
return code in (204, 304) or 100 <= code < 200

0 comments on commit f459e8e

Please sign in to comment.