MCPcopy Create free account
hub / github.com/EasyIME/PIME / parse_request_start_line

Function parse_request_start_line

python/python3/tornado/httputil.py:883–901  ·  view source on GitHub ↗

Returns a (method, path, version) tuple for an HTTP 1.x request line. The response is a `collections.namedtuple`. >>> parse_request_start_line("GET /foo HTTP/1.1") RequestStartLine(method='GET', path='/foo', version='HTTP/1.1')

(line: str)

Source from the content-addressed store, hash-verified

881
882
883def parse_request_start_line(line: str) -> RequestStartLine:
884 """Returns a (method, path, version) tuple for an HTTP 1.x request line.
885
886 The response is a `collections.namedtuple`.
887
888 >>> parse_request_start_line("GET /foo HTTP/1.1")
889 RequestStartLine(method='GET', path='/foo', version='HTTP/1.1')
890 """
891 try:
892 method, path, version = line.split(" ")
893 except ValueError:
894 # https://tools.ietf.org/html/rfc7230#section-3.1.1
895 # invalid request-line SHOULD respond with a 400 (Bad Request)
896 raise HTTPInputError("Malformed HTTP request line")
897 if not _http_version_re.match(version):
898 raise HTTPInputError(
899 "Malformed HTTP version in HTTP Request-Line: %r" % version
900 )
901 return RequestStartLine(method, path, version)
902
903
904ResponseStartLine = collections.namedtuple(

Callers 1

Calls 3

HTTPInputErrorClass · 0.85
splitMethod · 0.80
matchMethod · 0.45

Tested by 1