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)
| 881 | |
| 882 | |
| 883 | def 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 | |
| 904 | ResponseStartLine = collections.namedtuple( |