Skip to content
Myr

test_responses.py

This file

Path

tests/models/test_responses.py

970 lines · 26.4 KiB · Python

Last changed by

Ensure that iter_bytes does not ever yield any zero-length chunks (#2068)Tom Christiebefore adoption420911b

History of this file

Take it

1import json2import pickle34import pytest56import httpx7from httpx._compat import brotli8910class StreamingBody:11    def __iter__(self):12        yield b"Hello, "13        yield b"world!"141516def streaming_body():17    yield b"Hello, "18    yield b"world!"192021async def async_streaming_body():22    yield b"Hello, "23    yield b"world!"242526def test_response():27    response = httpx.Response(28        200,29        content=b"Hello, world!",30        request=httpx.Request("GET", "https://example.org"),31    )3233    assert response.status_code == 20034    assert response.reason_phrase == "OK"35    assert response.text == "Hello, world!"36    assert response.request.method == "GET"37    assert response.request.url == "https://example.org"38    assert not response.is_error394041def test_response_content():42    response = httpx.Response(200, content="Hello, world!")4344    assert response.status_code == 20045    assert response.reason_phrase == "OK"46    assert response.text == "Hello, world!"47    assert response.headers == {"Content-Length": "13"}484950def test_response_text():51    response = httpx.Response(200, text="Hello, world!")5253    assert response.status_code == 20054    assert response.reason_phrase == "OK"55    assert response.text == "Hello, world!"56    assert response.headers == {57        "Content-Length": "13",58        "Content-Type": "text/plain; charset=utf-8",59    }606162def test_response_html():63    response = httpx.Response(200, html="<html><body>Hello, world!</html></body>")6465    assert response.status_code == 20066    assert response.reason_phrase == "OK"67    assert response.text == "<html><body>Hello, world!</html></body>"68    assert response.headers == {69        "Content-Length": "39",70        "Content-Type": "text/html; charset=utf-8",71    }727374def test_response_json():75    response = httpx.Response(200, json={"hello": "world"})7677    assert response.status_code == 20078    assert response.reason_phrase == "OK"79    assert response.json() == {"hello": "world"}80    assert response.headers == {81        "Content-Length": "18",82        "Content-Type": "application/json",83    }848586def test_raise_for_status():87    request = httpx.Request("GET", "https://example.org")8889    # 2xx status codes are not an error.90    response = httpx.Response(200, request=request)91    response.raise_for_status()9293    # 1xx status codes are informational responses.94    response = httpx.Response(101, request=request)95    assert response.is_informational96    with pytest.raises(httpx.HTTPStatusError) as exc_info:97        response.raise_for_status()98    assert str(exc_info.value) == (99        "Informational response '101 Switching Protocols' for url 'https://example.org'\n"100        "For more information check: https://httpstatuses.com/101"101    )102103    # 3xx status codes are redirections.104    headers = {"location": "https://other.org"}105    response = httpx.Response(303, headers=headers, request=request)106    assert response.is_redirect107    with pytest.raises(httpx.HTTPStatusError) as exc_info:108        response.raise_for_status()109    assert str(exc_info.value) == (110        "Redirect response '303 See Other' for url 'https://example.org'\n"111        "Redirect location: 'https://other.org'\n"112        "For more information check: https://httpstatuses.com/303"113    )114115    # 4xx status codes are a client error.116    response = httpx.Response(403, request=request)117    assert response.is_client_error118    assert response.is_error119    with pytest.raises(httpx.HTTPStatusError) as exc_info:120        response.raise_for_status()121    assert str(exc_info.value) == (122        "Client error '403 Forbidden' for url 'https://example.org'\n"123        "For more information check: https://httpstatuses.com/403"124    )125126    # 5xx status codes are a server error.127    response = httpx.Response(500, request=request)128    assert response.is_server_error129    assert response.is_error130    with pytest.raises(httpx.HTTPStatusError) as exc_info:131        response.raise_for_status()132    assert str(exc_info.value) == (133        "Server error '500 Internal Server Error' for url 'https://example.org'\n"134        "For more information check: https://httpstatuses.com/500"135    )136137    # Calling .raise_for_status without setting a request instance is138    # not valid. Should raise a runtime error.139    response = httpx.Response(200)140    with pytest.raises(RuntimeError):141        response.raise_for_status()142143144def test_response_repr():145    response = httpx.Response(146        200,147        content=b"Hello, world!",148    )149    assert repr(response) == "<Response [200 OK]>"150151152def test_response_content_type_encoding():153    """154    Use the charset encoding in the Content-Type header if possible.155    """156    headers = {"Content-Type": "text-plain; charset=latin-1"}157    content = "Latin 1: ÿ".encode("latin-1")158    response = httpx.Response(159        200,160        content=content,161        headers=headers,162    )163    assert response.text == "Latin 1: ÿ"164    assert response.encoding == "latin-1"165166167def test_response_autodetect_encoding():168    """169    Autodetect encoding if there is no Content-Type header.170    """171    content = "おはようございます。".encode("utf-8")172    response = httpx.Response(173        200,174        content=content,175    )176    assert response.text == "おはようございます。"177    assert response.encoding is None178179180def test_response_fallback_to_autodetect():181    """182    Fallback to autodetection if we get an invalid charset in the Content-Type header.183    """184    headers = {"Content-Type": "text-plain; charset=invalid-codec-name"}185    content = "おはようございます。".encode("utf-8")186    response = httpx.Response(187        200,188        content=content,189        headers=headers,190    )191    assert response.text == "おはようございます。"192    assert response.encoding is None193194195def test_response_no_charset_with_ascii_content():196    """197    A response with ascii encoded content should decode correctly,198    even with no charset specified.199    """200    content = b"Hello, world!"201    headers = {"Content-Type": "text/plain"}202    response = httpx.Response(203        200,204        content=content,205        headers=headers,206    )207    assert response.status_code == 200208    assert response.encoding is None209    assert response.text == "Hello, world!"210211212def test_response_no_charset_with_utf8_content():213    """214    A response with UTF-8 encoded content should decode correctly,215    even with no charset specified.216    """217    content = "Unicode Snowman: ☃".encode("utf-8")218    headers = {"Content-Type": "text/plain"}219    response = httpx.Response(220        200,221        content=content,222        headers=headers,223    )224    assert response.text == "Unicode Snowman: ☃"225    assert response.encoding is None226227228def test_response_no_charset_with_iso_8859_1_content():229    """230    A response with ISO 8859-1 encoded content should decode correctly,231    even with no charset specified.232    """233    content = "Accented: Österreich abcdefghijklmnopqrstuzwxyz".encode("iso-8859-1")234    headers = {"Content-Type": "text/plain"}235    response = httpx.Response(236        200,237        content=content,238        headers=headers,239    )240    assert response.text == "Accented: Österreich abcdefghijklmnopqrstuzwxyz"241    assert response.charset_encoding is None242    assert response.apparent_encoding is not None243244245def test_response_no_charset_with_cp_1252_content():246    """247    A response with Windows 1252 encoded content should decode correctly,248    even with no charset specified.249    """250    content = "Euro Currency: € abcdefghijklmnopqrstuzwxyz".encode("cp1252")251    headers = {"Content-Type": "text/plain"}252    response = httpx.Response(253        200,254        content=content,255        headers=headers,256    )257    assert response.text == "Euro Currency: € abcdefghijklmnopqrstuzwxyz"258    assert response.charset_encoding is None259    assert response.apparent_encoding is not None260261262def test_response_non_text_encoding():263    """264    Default to apparent encoding for non-text content-type headers.265    """266    headers = {"Content-Type": "image/png"}267    response = httpx.Response(268        200,269        content=b"xyz",270        headers=headers,271    )272    assert response.text == "xyz"273    assert response.encoding is None274275276def test_response_set_explicit_encoding():277    headers = {278        "Content-Type": "text-plain; charset=utf-8"279    }  # Deliberately incorrect charset280    response = httpx.Response(281        200,282        content="Latin 1: ÿ".encode("latin-1"),283        headers=headers,284    )285    response.encoding = "latin-1"286    assert response.text == "Latin 1: ÿ"287    assert response.encoding == "latin-1"288289290def test_response_force_encoding():291    response = httpx.Response(292        200,293        content="Snowman: ☃".encode("utf-8"),294    )295    response.encoding = "iso-8859-1"296    assert response.status_code == 200297    assert response.reason_phrase == "OK"298    assert response.text == "Snowman: â\x98\x83"299    assert response.encoding == "iso-8859-1"300301302def test_read():303    response = httpx.Response(304        200,305        content=b"Hello, world!",306    )307308    assert response.status_code == 200309    assert response.text == "Hello, world!"310    assert response.encoding is None311    assert response.is_closed312313    content = response.read()314315    assert content == b"Hello, world!"316    assert response.content == b"Hello, world!"317    assert response.is_closed318319320def test_empty_read():321    response = httpx.Response(200)322323    assert response.status_code == 200324    assert response.text == ""325    assert response.encoding is None326    assert response.is_closed327328    content = response.read()329330    assert content == b""331    assert response.content == b""332    assert response.is_closed333334335@pytest.mark.asyncio336async def test_aread():337    response = httpx.Response(338        200,339        content=b"Hello, world!",340    )341342    assert response.status_code == 200343    assert response.text == "Hello, world!"344    assert response.encoding is None345    assert response.is_closed346347    content = await response.aread()348349    assert content == b"Hello, world!"350    assert response.content == b"Hello, world!"351    assert response.is_closed352353354@pytest.mark.asyncio355async def test_empty_aread():356    response = httpx.Response(200)357358    assert response.status_code == 200359    assert response.text == ""360    assert response.encoding is None361    assert response.is_closed362363    content = await response.aread()364365    assert content == b""366    assert response.content == b""367    assert response.is_closed368369370def test_iter_raw():371    response = httpx.Response(372        200,373        content=streaming_body(),374    )375376    raw = b""377    for part in response.iter_raw():378        raw += part379    assert raw == b"Hello, world!"380381382def test_iter_raw_with_chunksize():383    response = httpx.Response(200, content=streaming_body())384385    parts = [part for part in response.iter_raw(chunk_size=5)]386    assert parts == [b"Hello", b", wor", b"ld!"]387388    response = httpx.Response(200, content=streaming_body())389390    parts = [part for part in response.iter_raw(chunk_size=13)]391    assert parts == [b"Hello, world!"]392393    response = httpx.Response(200, content=streaming_body())394395    parts = [part for part in response.iter_raw(chunk_size=20)]396    assert parts == [b"Hello, world!"]397398399def test_iter_raw_doesnt_return_empty_chunks():400    def streaming_body_with_empty_chunks():401        yield b"Hello, "402        yield b""403        yield b"world!"404        yield b""405406    response = httpx.Response(200, content=streaming_body_with_empty_chunks())407408    parts = [part for part in response.iter_raw()]409    assert parts == [b"Hello, ", b"world!"]410411412def test_iter_raw_on_iterable():413    response = httpx.Response(414        200,415        content=StreamingBody(),416    )417418    raw = b""419    for part in response.iter_raw():420        raw += part421    assert raw == b"Hello, world!"422423424def test_iter_raw_on_async():425    response = httpx.Response(426        200,427        content=async_streaming_body(),428    )429430    with pytest.raises(RuntimeError):431        [part for part in response.iter_raw()]432433434def test_close_on_async():435    response = httpx.Response(436        200,437        content=async_streaming_body(),438    )439440    with pytest.raises(RuntimeError):441        response.close()442443444def test_iter_raw_increments_updates_counter():445    response = httpx.Response(200, content=streaming_body())446447    num_downloaded = response.num_bytes_downloaded448    for part in response.iter_raw():449        assert len(part) == (response.num_bytes_downloaded - num_downloaded)450        num_downloaded = response.num_bytes_downloaded451452453@pytest.mark.asyncio454async def test_aiter_raw():455    response = httpx.Response(200, content=async_streaming_body())456457    raw = b""458    async for part in response.aiter_raw():459        raw += part460    assert raw == b"Hello, world!"461462463@pytest.mark.asyncio464async def test_aiter_raw_with_chunksize():465    response = httpx.Response(200, content=async_streaming_body())466467    parts = [part async for part in response.aiter_raw(chunk_size=5)]468    assert parts == [b"Hello", b", wor", b"ld!"]469470    response = httpx.Response(200, content=async_streaming_body())471472    parts = [part async for part in response.aiter_raw(chunk_size=13)]473    assert parts == [b"Hello, world!"]474475    response = httpx.Response(200, content=async_streaming_body())476477    parts = [part async for part in response.aiter_raw(chunk_size=20)]478    assert parts == [b"Hello, world!"]479480481@pytest.mark.asyncio482async def test_aiter_raw_on_sync():483    response = httpx.Response(484        200,485        content=streaming_body(),486    )487488    with pytest.raises(RuntimeError):489        [part async for part in response.aiter_raw()]490491492@pytest.mark.asyncio493async def test_aclose_on_sync():494    response = httpx.Response(495        200,496        content=streaming_body(),497    )498499    with pytest.raises(RuntimeError):500        await response.aclose()501502503@pytest.mark.asyncio504async def test_aiter_raw_increments_updates_counter():505    response = httpx.Response(200, content=async_streaming_body())506507    num_downloaded = response.num_bytes_downloaded508    async for part in response.aiter_raw():509        assert len(part) == (response.num_bytes_downloaded - num_downloaded)510        num_downloaded = response.num_bytes_downloaded511512513def test_iter_bytes():514    response = httpx.Response(200, content=b"Hello, world!")515516    content = b""517    for part in response.iter_bytes():518        content += part519    assert content == b"Hello, world!"520521522def test_iter_bytes_with_chunk_size():523    response = httpx.Response(200, content=streaming_body())524    parts = [part for part in response.iter_bytes(chunk_size=5)]525    assert parts == [b"Hello", b", wor", b"ld!"]526527    response = httpx.Response(200, content=streaming_body())528    parts = [part for part in response.iter_bytes(chunk_size=13)]529    assert parts == [b"Hello, world!"]530531    response = httpx.Response(200, content=streaming_body())532    parts = [part for part in response.iter_bytes(chunk_size=20)]533    assert parts == [b"Hello, world!"]534535536def test_iter_bytes_with_empty_response():537    response = httpx.Response(200, content=b"")538    parts = [part for part in response.iter_bytes()]539    assert parts == []540541542def test_iter_bytes_doesnt_return_empty_chunks():543    def streaming_body_with_empty_chunks():544        yield b"Hello, "545        yield b""546        yield b"world!"547        yield b""548549    response = httpx.Response(200, content=streaming_body_with_empty_chunks())550551    parts = [part for part in response.iter_bytes()]552    assert parts == [b"Hello, ", b"world!"]553554555@pytest.mark.asyncio556async def test_aiter_bytes():557    response = httpx.Response(558        200,559        content=b"Hello, world!",560    )561562    content = b""563    async for part in response.aiter_bytes():564        content += part565    assert content == b"Hello, world!"566567568@pytest.mark.asyncio569async def test_aiter_bytes_with_chunk_size():570    response = httpx.Response(200, content=async_streaming_body())571    parts = [part async for part in response.aiter_bytes(chunk_size=5)]572    assert parts == [b"Hello", b", wor", b"ld!"]573574    response = httpx.Response(200, content=async_streaming_body())575    parts = [part async for part in response.aiter_bytes(chunk_size=13)]576    assert parts == [b"Hello, world!"]577578    response = httpx.Response(200, content=async_streaming_body())579    parts = [part async for part in response.aiter_bytes(chunk_size=20)]580    assert parts == [b"Hello, world!"]581582583def test_iter_text():584    response = httpx.Response(585        200,586        content=b"Hello, world!",587    )588589    content = ""590    for part in response.iter_text():591        content += part592    assert content == "Hello, world!"593594595def test_iter_text_with_chunk_size():596    response = httpx.Response(200, content=b"Hello, world!")597    parts = [part for part in response.iter_text(chunk_size=5)]598    assert parts == ["Hello", ", wor", "ld!"]599600    response = httpx.Response(200, content=b"Hello, world!")601    parts = [part for part in response.iter_text(chunk_size=13)]602    assert parts == ["Hello, world!"]603604    response = httpx.Response(200, content=b"Hello, world!")605    parts = [part for part in response.iter_text(chunk_size=20)]606    assert parts == ["Hello, world!"]607608609@pytest.mark.asyncio610async def test_aiter_text():611    response = httpx.Response(612        200,613        content=b"Hello, world!",614    )615616    content = ""617    async for part in response.aiter_text():618        content += part619    assert content == "Hello, world!"620621622@pytest.mark.asyncio623async def test_aiter_text_with_chunk_size():624    response = httpx.Response(200, content=b"Hello, world!")625    parts = [part async for part in response.aiter_text(chunk_size=5)]626    assert parts == ["Hello", ", wor", "ld!"]627628    response = httpx.Response(200, content=b"Hello, world!")629    parts = [part async for part in response.aiter_text(chunk_size=13)]630    assert parts == ["Hello, world!"]631632    response = httpx.Response(200, content=b"Hello, world!")633    parts = [part async for part in response.aiter_text(chunk_size=20)]634    assert parts == ["Hello, world!"]635636637def test_iter_lines():638    response = httpx.Response(639        200,640        content=b"Hello,\nworld!",641    )642    content = [line for line in response.iter_lines()]643    assert content == ["Hello,\n", "world!"]644645646@pytest.mark.asyncio647async def test_aiter_lines():648    response = httpx.Response(649        200,650        content=b"Hello,\nworld!",651    )652653    content = []654    async for line in response.aiter_lines():655        content.append(line)656    assert content == ["Hello,\n", "world!"]657658659def test_sync_streaming_response():660    response = httpx.Response(661        200,662        content=streaming_body(),663    )664665    assert response.status_code == 200666    assert not response.is_closed667668    content = response.read()669670    assert content == b"Hello, world!"671    assert response.content == b"Hello, world!"672    assert response.is_closed673674675@pytest.mark.asyncio676async def test_async_streaming_response():677    response = httpx.Response(678        200,679        content=async_streaming_body(),680    )681682    assert response.status_code == 200683    assert not response.is_closed684685    content = await response.aread()686687    assert content == b"Hello, world!"688    assert response.content == b"Hello, world!"689    assert response.is_closed690691692def test_cannot_read_after_stream_consumed():693    response = httpx.Response(694        200,695        content=streaming_body(),696    )697698    content = b""699    for part in response.iter_bytes():700        content += part701702    with pytest.raises(httpx.StreamConsumed):703        response.read()704705706@pytest.mark.asyncio707async def test_cannot_aread_after_stream_consumed():708    response = httpx.Response(709        200,710        content=async_streaming_body(),711    )712713    content = b""714    async for part in response.aiter_bytes():715        content += part716717    with pytest.raises(httpx.StreamConsumed):718        await response.aread()719720721def test_cannot_read_after_response_closed():722    response = httpx.Response(723        200,724        content=streaming_body(),725    )726727    response.close()728    with pytest.raises(httpx.StreamClosed):729        response.read()730731732@pytest.mark.asyncio733async def test_cannot_aread_after_response_closed():734    response = httpx.Response(735        200,736        content=async_streaming_body(),737    )738739    await response.aclose()740    with pytest.raises(httpx.StreamClosed):741        await response.aread()742743744@pytest.mark.asyncio745async def test_elapsed_not_available_until_closed():746    response = httpx.Response(747        200,748        content=async_streaming_body(),749    )750751    with pytest.raises(RuntimeError):752        response.elapsed753754755def test_unknown_status_code():756    response = httpx.Response(757        600,758    )759    assert response.status_code == 600760    assert response.reason_phrase == ""761    assert response.text == ""762763764def test_json_with_specified_encoding():765    data = {"greeting": "hello", "recipient": "world"}766    content = json.dumps(data).encode("utf-16")767    headers = {"Content-Type": "application/json, charset=utf-16"}768    response = httpx.Response(769        200,770        content=content,771        headers=headers,772    )773    assert response.json() == data774775776def test_json_with_options():777    data = {"greeting": "hello", "recipient": "world", "amount": 1}778    content = json.dumps(data).encode("utf-16")779    headers = {"Content-Type": "application/json, charset=utf-16"}780    response = httpx.Response(781        200,782        content=content,783        headers=headers,784    )785    assert response.json(parse_int=str)["amount"] == "1"786787788@pytest.mark.parametrize(789    "encoding",790    [791        "utf-8",792        "utf-8-sig",793        "utf-16",794        "utf-16-be",795        "utf-16-le",796        "utf-32",797        "utf-32-be",798        "utf-32-le",799    ],800)801def test_json_without_specified_charset(encoding):802    data = {"greeting": "hello", "recipient": "world"}803    content = json.dumps(data).encode(encoding)804    headers = {"Content-Type": "application/json"}805    response = httpx.Response(806        200,807        content=content,808        headers=headers,809    )810    assert response.json() == data811812813@pytest.mark.parametrize(814    "encoding",815    [816        "utf-8",817        "utf-8-sig",818        "utf-16",819        "utf-16-be",820        "utf-16-le",821        "utf-32",822        "utf-32-be",823        "utf-32-le",824    ],825)826def test_json_with_specified_charset(encoding):827    data = {"greeting": "hello", "recipient": "world"}828    content = json.dumps(data).encode(encoding)829    headers = {"Content-Type": f"application/json; charset={encoding}"}830    response = httpx.Response(831        200,832        content=content,833        headers=headers,834    )835    assert response.json() == data836837838@pytest.mark.parametrize(839    "headers, expected",840    [841        (842            {"Link": "<https://example.com>; rel='preload'"},843            {"preload": {"rel": "preload", "url": "https://example.com"}},844        ),845        (846            {"Link": '</hub>; rel="hub", </resource>; rel="self"'},847            {848                "hub": {"url": "/hub", "rel": "hub"},849                "self": {"url": "/resource", "rel": "self"},850            },851        ),852    ],853)854def test_link_headers(headers, expected):855    response = httpx.Response(856        200,857        content=None,858        headers=headers,859    )860    assert response.links == expected861862863@pytest.mark.parametrize("header_value", (b"deflate", b"gzip", b"br"))864def test_decode_error_with_request(header_value):865    headers = [(b"Content-Encoding", header_value)]866    body = b"test 123"867    compressed_body = brotli.compress(body)[3:]868    with pytest.raises(httpx.DecodingError):869        httpx.Response(870            200,871            headers=headers,872            content=compressed_body,873        )874875    with pytest.raises(httpx.DecodingError):876        httpx.Response(877            200,878            headers=headers,879            content=compressed_body,880            request=httpx.Request("GET", "https://www.example.org/"),881        )882883884@pytest.mark.parametrize("header_value", (b"deflate", b"gzip", b"br"))885def test_value_error_without_request(header_value):886    headers = [(b"Content-Encoding", header_value)]887    body = b"test 123"888    compressed_body = brotli.compress(body)[3:]889    with pytest.raises(httpx.DecodingError):890        httpx.Response(200, headers=headers, content=compressed_body)891892893def test_response_with_unset_request():894    response = httpx.Response(200, content=b"Hello, world!")895896    assert response.status_code == 200897    assert response.reason_phrase == "OK"898    assert response.text == "Hello, world!"899    assert not response.is_error900901902def test_set_request_after_init():903    response = httpx.Response(200, content=b"Hello, world!")904905    response.request = httpx.Request("GET", "https://www.example.org")906907    assert response.request.method == "GET"908    assert response.request.url == "https://www.example.org"909910911def test_cannot_access_unset_request():912    response = httpx.Response(200, content=b"Hello, world!")913914    with pytest.raises(RuntimeError):915        response.request916917918def test_generator_with_transfer_encoding_header():919    def content():920        yield b"test 123"  # pragma: nocover921922    response = httpx.Response(200, content=content())923    assert response.headers == {"Transfer-Encoding": "chunked"}924925926def test_generator_with_content_length_header():927    def content():928        yield b"test 123"  # pragma: nocover929930    headers = {"Content-Length": "8"}931    response = httpx.Response(200, content=content(), headers=headers)932    assert response.headers == {"Content-Length": "8"}933934935def test_response_picklable():936    response = httpx.Response(937        200,938        content=b"Hello, world!",939        request=httpx.Request("GET", "https://example.org"),940    )941    pickle_response = pickle.loads(pickle.dumps(response))942    assert pickle_response.is_closed is True943    assert pickle_response.is_stream_consumed is True944    assert pickle_response.next_request is None945    assert pickle_response.stream is not None946    assert pickle_response.content == b"Hello, world!"947    assert pickle_response.status_code == 200948    assert pickle_response.request.url == response.request.url949    assert pickle_response.extensions == {}950    assert pickle_response.history == []951952953@pytest.mark.asyncio954async def test_response_async_streaming_picklable():955    response = httpx.Response(200, content=async_streaming_body())956    pickle_response = pickle.loads(pickle.dumps(response))957    with pytest.raises(httpx.ResponseNotRead):958        pickle_response.content959    with pytest.raises(httpx.StreamClosed):960        await pickle_response.aread()961    assert pickle_response.is_stream_consumed is False962    assert pickle_response.num_bytes_downloaded == 0963    assert pickle_response.headers == {"Transfer-Encoding": "chunked"}964965    response = httpx.Response(200, content=async_streaming_body())966    await response.aread()967    pickle_response = pickle.loads(pickle.dumps(response))968    assert pickle_response.is_stream_consumed is True969    assert pickle_response.content == b"Hello, world!"970    assert pickle_response.num_bytes_downloaded == 13