def read_response_head(rfile): """ Parse an HTTP response head (response line + headers) from an input stream Args: rfile: The input stream Returns: The HTTP request object (without body) Raises: exceptions.HttpReadDisconnect: No bytes can be read from rfile. exceptions.HttpSyntaxException: The input is malformed HTTP. exceptions.HttpException: Any other error occured. """ timestamp_start = time.time() if hasattr(rfile, "reset_timestamps"): rfile.reset_timestamps() http_version, status_code, message = _read_response_line(rfile) headers = _read_headers(rfile) if hasattr(rfile, "first_byte_timestamp"): # more accurate timestamp_start timestamp_start = rfile.first_byte_timestamp return response.Response(http_version, status_code, message, headers, None, timestamp_start)
def read_response_head(lines: List[bytes]) -> response.Response: """ Parse an HTTP response head (response line + headers) from an iterable of lines Args: lines: The input lines Returns: The HTTP response object (without body) Raises: ValueError: The input is malformed. """ http_version, status_code, reason = _read_response_line(lines[0]) headers = _read_headers(lines[1:]) return response.Response( http_version=http_version, status_code=status_code, reason=reason, headers=headers, content=None, trailers=None, timestamp_start=time.time(), timestamp_end=None, )