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

Respond 400 to malformed methods instead of 405 #3338

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all 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
5 changes: 5 additions & 0 deletions tornado/httputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ class RequestStartLine(typing.NamedTuple):


_http_version_re = re.compile(r"^HTTP/1\.[0-9]$")
_http_method_re = re.compile(r"^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$")


def parse_request_start_line(line: str) -> RequestStartLine:
Expand All @@ -909,6 +910,10 @@ def parse_request_start_line(line: str) -> RequestStartLine:
raise HTTPInputError(
"Malformed HTTP version in HTTP Request-Line: %r" % version
)
if not _http_method_re.match(method):
raise HTTPInputError(
"Malformed method in HTTP Request-line: %r" % method
)
return RequestStartLine(method, path, version)


Expand Down