Skip to content

Commit

Permalink
Add HTTP method validation (aio-libs#6533) (aio-libs#7806)
Browse files Browse the repository at this point in the history
(cherry picked from commit 75fca0b)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
  • Loading branch information
2 people authored and Xiang Li committed Dec 4, 2023
1 parent 7351591 commit 17c24b0
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 191 deletions.
1 change: 1 addition & 0 deletions CHANGES/6533.feature
@@ -0,0 +1 @@
Add HTTP method validation.
9 changes: 8 additions & 1 deletion aiohttp/client_reqrep.py
Expand Up @@ -81,6 +81,7 @@
from .tracing import Trace


_CONTAINS_CONTROL_CHAR_RE = re.compile(r"[^-!#$%&'*+.^_`|~0-9a-zA-Z]")
json_re = re.compile(r"^application/(?:[\w.+-]+?\+)?json")


Expand Down Expand Up @@ -275,10 +276,16 @@ def __init__(
trust_env: bool = False,
server_hostname: Optional[str] = None,
):

if loop is None:
loop = asyncio.get_event_loop()

match = _CONTAINS_CONTROL_CHAR_RE.search(method)
if match:
raise ValueError(
f"Method cannot contain non-token characters {method!r} "
"(found at least {match.group()!r})"
)

assert isinstance(url, URL), url
assert isinstance(proxy, (URL, type(None))), proxy
# FIXME: session is None in tests only, need to fix tests
Expand Down

0 comments on commit 17c24b0

Please sign in to comment.