Read an HTTP/1.1 response from ``stream``.

    ``stream`` is an :class:`~asyncio.StreamReader`.

    Return ``(status_code, reason, headers)`` where ``status_code`` is an
    :class:`int`, ``reason`` is a :class:`str`, and ``headers`` is a
    :class:`Headers` instance.

    Non-ASCII characters are represented with surrogate escapes.

    Raise an exception if the response isn't well formatted.

    Don't attempt to read the response body, because WebSocket handshake
    responses don't have one. If the response contains a body, it may be
    read from ``stream`` after this coroutine returns.

async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, "Headers"]:
    """
    Read an HTTP/1.1 response from ``stream``.

    ``stream`` is an :class:`~asyncio.StreamReader`.

    Return ``(status_code, reason, headers)`` where ``status_code`` is an
    :class:`int`, ``reason`` is a :class:`str`, and ``headers`` is a
    :class:`Headers` instance.

    Non-ASCII characters are represented with surrogate escapes.

    Raise an exception if the response isn't well formatted.

    Don't attempt to read the response body, because WebSocket handshake
    responses don't have one. If the response contains a body, it may be
    read from ``stream`` after this coroutine returns.

    """
    # https://tools.ietf.org/html/rfc7230#section-3.1.2

    # As in read_request, parsing is simple because a fixed value is expected
    # for version, status_code is a 3-digit number, and reason can be ignored.

    status_line = await read_line(stream)

    # This may raise "ValueError: not enough values to unpack"
    version, raw_status_code, raw_reason = status_line.split(b" ", 2)

    if version != b"HTTP/1.1":
        raise ValueError("Unsupported HTTP version: %r" % version)
    # This may raise "ValueError: invalid literal for int() with base 10"
    status_code = int(raw_status_code)
    if not 100 <= status_code < 1000:
        raise ValueError("Unsupported HTTP status code: %d" % status_code)
    if not _value_re.fullmatch(raw_reason):
        raise ValueError("Invalid HTTP reason phrase: %r" % raw_reason)
    reason = raw_reason.decode()

    headers = await read_headers(stream)

    return status_code, reason, headers