MCPcopy
hub / github.com/tornadoweb/tornado / parse_response_start_line

Function parse_response_start_line

tornado/httputil.py:1170–1185  ·  view source on GitHub ↗

Returns a (version, code, reason) tuple for an HTTP 1.x response line. The response is a `typing.NamedTuple`. >>> parse_response_start_line("HTTP/1.1 200 OK") ResponseStartLine(version='HTTP/1.1', code=200, reason='OK')

(line: str)

Source from the content-addressed store, hash-verified

1168
1169
1170def parse_response_start_line(line: str) -> ResponseStartLine:
1171 """Returns a (version, code, reason) tuple for an HTTP 1.x response line.
1172
1173 The response is a `typing.NamedTuple`.
1174
1175 >>> parse_response_start_line("HTTP/1.1 200 OK")
1176 ResponseStartLine(version='HTTP/1.1', code=200, reason='OK')
1177 """
1178 match = _ABNF.status_line.fullmatch(line)
1179 if not match:
1180 raise HTTPInputError("Error parsing response start line")
1181 r = ResponseStartLine(match.group(1), int(match.group(2)), match.group(3))
1182 if not r.version.startswith("HTTP/1"):
1183 # HTTP/2 and above doesn't use parse_response_start_line.
1184 raise HTTPInputError("Unexpected HTTP version %r" % r.version)
1185 return r
1186
1187
1188# _parseparam and _parse_header are copied and modified from python2.7's cgi.py

Callers

nothing calls this directly

Calls 2

HTTPInputErrorClass · 0.85
ResponseStartLineClass · 0.85

Tested by

no test coverage detected