Skip to content
Myr

test_responses.py

This file

Path

tests/models/test_responses.py

944 lines · 25.7 KiB · Python

Last changed by

is_informational / is_success / is_redirect / is_client_error / is_server_error (#1854)Tom Christiebefore adoptiona761e17

History of this file

Take it

The walk stopped after 200 commits: lines older than bd8165a point at it.

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 1why, one step back
1import json

Make Request and Response picklable (#1579)Hannes Ljungbergbefore adoption2d57104

line 2why, one step back
2import pickle

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 3–6why, one step back
3
4import pytest56import httpx

Use either brotli or brotlicffi. (#1618)Tom Christiebefore adoptiond514312

line 7why, one step back
7from httpx._compat import brotli

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 8–9why, one step back
8
9

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

lines 10–15why, one step back
10class StreamingBody:
11 def __iter__(self):12 yield b"Hello, "13 yield b"world!"1415

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 16–25why, one step back
16def streaming_body():
17 yield b"Hello, "18 yield b"world!"192021async def async_streaming_body():22 yield b"Hello, "23 yield b"world!"2425

Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205

line 26why, one step back
26def test_response():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 27–31why, one step back
27 response = httpx.Response(
28 200,29 content=b"Hello, world!",30 request=httpx.Request("GET", "https://example.org"),31 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 32–35why, one step back
32
33 assert response.status_code == 20034 assert response.reason_phrase == "OK"35 assert response.text == "Hello, world!"

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 36–37why, one step back
36 assert response.request.method == "GET"
37 assert response.request.url == "https://example.org"

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 38–40why, one step back
38 assert not response.is_error
3940

Fix automatic .read() when Response instances are created with content=<str> (#1324)Tom Christiebefore adoption666cbbd

lines 41–46why, one step back
41def 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!"

Support header comparisons with dict or list. (#1326)Musale Martinbefore adoption815ef94

line 47why, one step back
47 assert response.headers == {"Content-Length": "13"}

Fix automatic .read() when Response instances are created with content=<str> (#1324)Tom Christiebefore adoption666cbbd

lines 48–49why, one step back
48
49

Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941

lines 50–55why, one step back
50def 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!"

Support header comparisons with dict or list. (#1326)Musale Martinbefore adoption815ef94

lines 56–59why, one step back
56 assert response.headers == {
57 "Content-Length": "13",58 "Content-Type": "text/plain; charset=utf-8",59 }

Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941

lines 60–67why, one step back
60
6162def 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>"

Support header comparisons with dict or list. (#1326)Musale Martinbefore adoption815ef94

lines 68–71why, one step back
68 assert response.headers == {
69 "Content-Length": "39",70 "Content-Type": "text/html; charset=utf-8",71 }

Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941

lines 72–79why, one step back
72
7374def 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"}

Support header comparisons with dict or list. (#1326)Musale Martinbefore adoption815ef94

lines 80–83why, one step back
80 assert response.headers == {
81 "Content-Length": "18",82 "Content-Type": "application/json",83 }

Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941

lines 84–85why, one step back
84
85

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

line 86why, one step back
86def test_raise_for_status():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 87–88why, one step back
87 request = httpx.Request("GET", "https://example.org")
88

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

line 89why, one step back
89 # 2xx status codes are not an error.

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 90why, one step back
90 response = httpx.Response(200, request=request)

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

lines 91–92why, one step back
91 response.raise_for_status()
92

is_informational / is_success / is_redirect / is_client_error / is_server_error (#1854)Tom Christiebefore adoptiona761e17

lines 93–114why, one step back
93 # 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 )114

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

line 115why, one step back
115 # 4xx status codes are a client error.

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 116why, one step back
116 response = httpx.Response(403, request=request)

is_informational / is_success / is_redirect / is_client_error / is_server_error (#1854)Tom Christiebefore adoptiona761e17

lines 117–119why, one step back
117 assert response.is_client_error
118 assert response.is_error119 with pytest.raises(httpx.HTTPStatusError) as exc_info:

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

line 120why, one step back
120 response.raise_for_status()

is_informational / is_success / is_redirect / is_client_error / is_server_error (#1854)Tom Christiebefore adoptiona761e17

lines 121–124why, one step back
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 )

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

lines 125–126why, one step back
125
126 # 5xx status codes are a server error.

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 127why, one step back
127 response = httpx.Response(500, request=request)

is_informational / is_success / is_redirect / is_client_error / is_server_error (#1854)Tom Christiebefore adoptiona761e17

lines 128–130why, one step back
128 assert response.is_server_error
129 assert response.is_error130 with pytest.raises(httpx.HTTPStatusError) as exc_info:

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

line 131why, one step back
131 response.raise_for_status()

is_informational / is_success / is_redirect / is_client_error / is_server_error (#1854)Tom Christiebefore adoptiona761e17

lines 132–135why, one step back
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 )

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

lines 136–143why, one step back
136
137 # 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()142143

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 144why, one step back
144def test_response_repr():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 145–148why, one step back
145 response = httpx.Response(
146 200,147 content=b"Hello, world!",148 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 149–157why, one step back
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")

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 158–162why, one step back
158 response = httpx.Response(
159 200,160 content=content,161 headers=headers,162 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 163–168why, one step back
163 assert response.text == "Latin 1: ÿ"
164 assert response.encoding == "latin-1"165166167def test_response_autodetect_encoding():168 """

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

line 169why, one step back
169 Autodetect encoding if there is no Content-Type header.

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 170why, one step back
170 """

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

line 171why, one step back
171 content = "おはようございます。".encode("utf-8")

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 172–175why, one step back
172 response = httpx.Response(
173 200,174 content=content,175 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 176why, one step back
176 assert response.text == "おはようございます。"

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

line 177why, one step back
177 assert response.encoding is None

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 178–184why, one step back
178
179180def 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"}

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

line 185why, one step back
185 content = "おはようございます。".encode("utf-8")

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 186–190why, one step back
186 response = httpx.Response(
187 200,188 content=content,189 headers=headers,190 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 191why, one step back
191 assert response.text == "おはようございます。"

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

line 192why, one step back
192 assert response.encoding is None

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 193–194why, one step back
193
194

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

line 195why, one step back
195def test_response_no_charset_with_ascii_content():

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 196why, one step back
196 """

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

lines 197–198why, one step back
197 A response with ascii encoded content should decode correctly,
198 even with no charset specified.

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 199–201why, one step back
199 """
200 content = b"Hello, world!"201 headers = {"Content-Type": "text/plain"}

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 202–206why, one step back
202 response = httpx.Response(
203 200,204 content=content,205 headers=headers,206 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 207why, one step back
207 assert response.status_code == 200

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

line 208why, one step back
208 assert response.encoding is None

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 209–211why, one step back
209 assert response.text == "Hello, world!"
210211

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

line 212why, one step back
212def test_response_no_charset_with_utf8_content():

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 213why, one step back
213 """

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

lines 214–215why, one step back
214 A response with UTF-8 encoded content should decode correctly,
215 even with no charset specified.

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 216why, one step back
216 """

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

lines 217–218why, one step back
217 content = "Unicode Snowman: ☃".encode("utf-8")
218 headers = {"Content-Type": "text/plain"}

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 219–220why, one step back
219 response = httpx.Response(
220 200,

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

lines 221–222why, one step back
221 content=content,
222 headers=headers,

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 223why, one step back
223 )

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

lines 224–225why, one step back
224 assert response.text == "Unicode Snowman: ☃"
225 assert response.encoding is None

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 226–227why, one step back
226
227

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

lines 228–232why, one step back
228def 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 """

Add `charset_normalizer` detection. (#1791)Tom Christiebefore adoptionacb5e6a

line 233why, one step back
233 content = "Accented: Österreich abcdefghijklmnopqrstuzwxyz".encode("iso-8859-1")

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

lines 234–239why, one step back
234 headers = {"Content-Type": "text/plain"}
235 response = httpx.Response(236 200,237 content=content,238 headers=headers,239 )

Add `charset_normalizer` detection. (#1791)Tom Christiebefore adoptionacb5e6a

lines 240–242why, one step back
240 assert response.text == "Accented: Österreich abcdefghijklmnopqrstuzwxyz"
241 assert response.charset_encoding is None242 assert response.apparent_encoding is not None

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

lines 243–249why, one step back
243
244245def 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 """

Add `charset_normalizer` detection. (#1791)Tom Christiebefore adoptionacb5e6a

line 250why, one step back
250 content = "Euro Currency: € abcdefghijklmnopqrstuzwxyz".encode("cp1252")

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

lines 251–256why, one step back
251 headers = {"Content-Type": "text/plain"}
252 response = httpx.Response(253 200,254 content=content,255 headers=headers,256 )

Add `charset_normalizer` detection. (#1791)Tom Christiebefore adoptionacb5e6a

lines 257–259why, one step back
257 assert response.text == "Euro Currency: € abcdefghijklmnopqrstuzwxyz"
258 assert response.charset_encoding is None259 assert response.apparent_encoding is not None

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

lines 260–261why, one step back
260
261

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 262–266why, one step back
262def test_response_non_text_encoding():
263 """264 Default to apparent encoding for non-text content-type headers.265 """266 headers = {"Content-Type": "image/png"}

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 267–271why, one step back
267 response = httpx.Response(
268 200,269 content=b"xyz",270 headers=headers,271 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 272why, one step back
272 assert response.text == "xyz"

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

line 273why, one step back
273 assert response.encoding is None

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 274–280why, one step back
274
275276def test_response_set_explicit_encoding():277 headers = {278 "Content-Type": "text-plain; charset=utf-8"279 } # Deliberately incorrect charset280 response = httpx.Response(

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 281–283why, one step back
281 200,
282 content="Latin 1: ÿ".encode("latin-1"),283 headers=headers,

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 284–291why, one step back
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(

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 292–293why, one step back
292 200,
293 content="Snowman: ☃".encode("utf-8"),

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 294–302why, one step back
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():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 303–306why, one step back
303 response = httpx.Response(
304 200,305 content=b"Hello, world!",306 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 307–309why, one step back
307
308 assert response.status_code == 200309 assert response.text == "Hello, world!"

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

line 310why, one step back
310 assert response.encoding is None

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 311–319why, one step back
311 assert response.is_closed
312313 content = response.read()314315 assert content == b"Hello, world!"316 assert response.content == b"Hello, world!"317 assert response.is_closed318319

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

lines 320–334why, one step back
320def 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_closed333334

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 335–336why, one step back
335@pytest.mark.asyncio
336async def test_aread():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 337–340why, one step back
337 response = httpx.Response(
338 200,339 content=b"Hello, world!",340 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 341–343why, one step back
341
342 assert response.status_code == 200343 assert response.text == "Hello, world!"

Drop chardet (#1269)Tom Christiebefore adoptiond0fe113

line 344why, one step back
344 assert response.encoding is None

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 345–353why, one step back
345 assert response.is_closed
346347 content = await response.aread()348349 assert content == b"Hello, world!"350 assert response.content == b"Hello, world!"351 assert response.is_closed352353

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

lines 354–369why, one step back
354@pytest.mark.asyncio
355async 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_closed368369

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 370why, one step back
370def test_iter_raw():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 371–372why, one step back
371 response = httpx.Response(
372 200,

Support `Response(content=<bytes iterator>)` (#1265)Tom Christiebefore adoption5ee6135

line 373why, one step back
373 content=streaming_body(),

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 374why, one step back
374 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 375–381why, one step back
375
376 raw = b""377 for part in response.iter_raw():378 raw += part379 assert raw == b"Hello, world!"380381

Support for `chunk_size` (#1277)Tom Christiebefore adoption27df5e4

lines 382–398why, one step back
382def 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!"]397398

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

lines 399–420why, one step back
399def test_iter_raw_on_iterable():
400 response = httpx.Response(401 200,402 content=StreamingBody(),403 )404405 raw = b""406 for part in response.iter_raw():407 raw += part408 assert raw == b"Hello, world!"409410411def test_iter_raw_on_async():412 response = httpx.Response(413 200,414 content=async_streaming_body(),415 )416417 with pytest.raises(RuntimeError):418 [part for part in response.iter_raw()]419420

Drop 'Response(on_close=...)' from API (#1572)Tom Christiebefore adoption073a328

lines 421–430why, one step back
421def test_close_on_async():
422 response = httpx.Response(423 200,424 content=async_streaming_body(),425 )426427 with pytest.raises(RuntimeError):428 response.close()429430

Add progress to streaming download (#1268)cdelerbefore adoptioned16eb3

line 431why, one step back
431def test_iter_raw_increments_updates_counter():

Support `Response(content=<bytes iterator>)` (#1265)Tom Christiebefore adoption5ee6135

line 432why, one step back
432 response = httpx.Response(200, content=streaming_body())

Add progress to streaming download (#1268)cdelerbefore adoptioned16eb3

lines 433–439why, one step back
433
434 num_downloaded = response.num_bytes_downloaded435 for part in response.iter_raw():436 assert len(part) == (response.num_bytes_downloaded - num_downloaded)437 num_downloaded = response.num_bytes_downloaded438439

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 440–441why, one step back
440@pytest.mark.asyncio
441async def test_aiter_raw():

Support `Response(content=<bytes iterator>)` (#1265)Tom Christiebefore adoption5ee6135

line 442why, one step back
442 response = httpx.Response(200, content=async_streaming_body())

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 443–447why, one step back
443
444 raw = b""445 async for part in response.aiter_raw():446 raw += part447 assert raw == b"Hello, world!"

Add progress to streaming download (#1268)cdelerbefore adoptioned16eb3

lines 448–450why, one step back
448
449450@pytest.mark.asyncio

Support for `chunk_size` (#1277)Tom Christiebefore adoption27df5e4

lines 451–468why, one step back
451async def test_aiter_raw_with_chunksize():
452 response = httpx.Response(200, content=async_streaming_body())453454 parts = [part async for part in response.aiter_raw(chunk_size=5)]455 assert parts == [b"Hello", b", wor", b"ld!"]456457 response = httpx.Response(200, content=async_streaming_body())458459 parts = [part async for part in response.aiter_raw(chunk_size=13)]460 assert parts == [b"Hello, world!"]461462 response = httpx.Response(200, content=async_streaming_body())463464 parts = [part async for part in response.aiter_raw(chunk_size=20)]465 assert parts == [b"Hello, world!"]466467468@pytest.mark.asyncio

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

lines 469–476why, one step back
469async def test_aiter_raw_on_sync():
470 response = httpx.Response(471 200,472 content=streaming_body(),473 )474475 with pytest.raises(RuntimeError):476 [part async for part in response.aiter_raw()]

Drop 'Response(on_close=...)' from API (#1572)Tom Christiebefore adoption073a328

lines 477–487why, one step back
477
478479@pytest.mark.asyncio480async def test_aclose_on_sync():481 response = httpx.Response(482 200,483 content=streaming_body(),484 )485486 with pytest.raises(RuntimeError):487 await response.aclose()

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

lines 488–490why, one step back
488
489490@pytest.mark.asyncio

Add progress to streaming download (#1268)cdelerbefore adoptioned16eb3

line 491why, one step back
491async def test_aiter_raw_increments_updates_counter():

Support `Response(content=<bytes iterator>)` (#1265)Tom Christiebefore adoption5ee6135

line 492why, one step back
492 response = httpx.Response(200, content=async_streaming_body())

Add progress to streaming download (#1268)cdelerbefore adoptioned16eb3

lines 493–497why, one step back
493
494 num_downloaded = response.num_bytes_downloaded495 async for part in response.aiter_raw():496 assert len(part) == (response.num_bytes_downloaded - num_downloaded)497 num_downloaded = response.num_bytes_downloaded

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 498–500why, one step back
498
499500def test_iter_bytes():

Support for `chunk_size` (#1277)Tom Christiebefore adoption27df5e4

line 501why, one step back
501 response = httpx.Response(200, content=b"Hello, world!")

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 502–508why, one step back
502
503 content = b""504 for part in response.iter_bytes():505 content += part506 assert content == b"Hello, world!"507508

Support for `chunk_size` (#1277)Tom Christiebefore adoption27df5e4

lines 509–522why, one step back
509def test_iter_bytes_with_chunk_size():
510 response = httpx.Response(200, content=streaming_body())511 parts = [part for part in response.iter_bytes(chunk_size=5)]512 assert parts == [b"Hello", b", wor", b"ld!"]513514 response = httpx.Response(200, content=streaming_body())515 parts = [part for part in response.iter_bytes(chunk_size=13)]516 assert parts == [b"Hello, world!"]517518 response = httpx.Response(200, content=streaming_body())519 parts = [part for part in response.iter_bytes(chunk_size=20)]520 assert parts == [b"Hello, world!"]521522

Fix iter_bytes with empty content (#1827)Tom Christiebefore adoption10b60d4

lines 523–528why, one step back
523def test_iter_bytes_with_empty_response():
524 response = httpx.Response(200, content=b"")525 parts = [part for part in response.iter_bytes()]526 assert parts == []527528

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 529–530why, one step back
529@pytest.mark.asyncio
530async def test_aiter_bytes():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 531–534why, one step back
531 response = httpx.Response(
532 200,533 content=b"Hello, world!",534 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 535–541why, one step back
535
536 content = b""537 async for part in response.aiter_bytes():538 content += part539 assert content == b"Hello, world!"540541

Support for `chunk_size` (#1277)Tom Christiebefore adoption27df5e4

lines 542–556why, one step back
542@pytest.mark.asyncio
543async def test_aiter_bytes_with_chunk_size():544 response = httpx.Response(200, content=async_streaming_body())545 parts = [part async for part in response.aiter_bytes(chunk_size=5)]546 assert parts == [b"Hello", b", wor", b"ld!"]547548 response = httpx.Response(200, content=async_streaming_body())549 parts = [part async for part in response.aiter_bytes(chunk_size=13)]550 assert parts == [b"Hello, world!"]551552 response = httpx.Response(200, content=async_streaming_body())553 parts = [part async for part in response.aiter_bytes(chunk_size=20)]554 assert parts == [b"Hello, world!"]555556

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 557why, one step back
557def test_iter_text():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 558–561why, one step back
558 response = httpx.Response(
559 200,560 content=b"Hello, world!",561 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 562–568why, one step back
562
563 content = ""564 for part in response.iter_text():565 content += part566 assert content == "Hello, world!"567568

Support for `chunk_size` (#1277)Tom Christiebefore adoption27df5e4

lines 569–582why, one step back
569def test_iter_text_with_chunk_size():
570 response = httpx.Response(200, content=b"Hello, world!")571 parts = [part for part in response.iter_text(chunk_size=5)]572 assert parts == ["Hello", ", wor", "ld!"]573574 response = httpx.Response(200, content=b"Hello, world!")575 parts = [part for part in response.iter_text(chunk_size=13)]576 assert parts == ["Hello, world!"]577578 response = httpx.Response(200, content=b"Hello, world!")579 parts = [part for part in response.iter_text(chunk_size=20)]580 assert parts == ["Hello, world!"]581582

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 583–584why, one step back
583@pytest.mark.asyncio
584async def test_aiter_text():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 585–588why, one step back
585 response = httpx.Response(
586 200,587 content=b"Hello, world!",588 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 589–593why, one step back
589
590 content = ""591 async for part in response.aiter_text():592 content += part593 assert content == "Hello, world!"

Support for `chunk_size` (#1277)Tom Christiebefore adoption27df5e4

lines 594–608why, one step back
594
595596@pytest.mark.asyncio597async def test_aiter_text_with_chunk_size():598 response = httpx.Response(200, content=b"Hello, world!")599 parts = [part async for part in response.aiter_text(chunk_size=5)]600 assert parts == ["Hello", ", wor", "ld!"]601602 response = httpx.Response(200, content=b"Hello, world!")603 parts = [part async for part in response.aiter_text(chunk_size=13)]604 assert parts == ["Hello, world!"]605606 response = httpx.Response(200, content=b"Hello, world!")607 parts = [part async for part in response.aiter_text(chunk_size=20)]608 assert parts == ["Hello, world!"]

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 609–611why, one step back
609
610611def test_iter_lines():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 612–615why, one step back
612 response = httpx.Response(
613 200,614 content=b"Hello,\nworld!",615 )

Replace for loops with comprehensions (#1759)Almazbefore adoptionb839478

line 616why, one step back
616 content = [line for line in response.iter_lines()]

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 617–621why, one step back
617 assert content == ["Hello,\n", "world!"]
618619620@pytest.mark.asyncio621async def test_aiter_lines():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 622–625why, one step back
622 response = httpx.Response(
623 200,624 content=b"Hello,\nworld!",625 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 626–633why, one step back
626
627 content = []628 async for line in response.aiter_lines():629 content.append(line)630 assert content == ["Hello,\n", "world!"]631632633def test_sync_streaming_response():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 634–635why, one step back
634 response = httpx.Response(
635 200,

Support `Response(content=<bytes iterator>)` (#1265)Tom Christiebefore adoption5ee6135

line 636why, one step back
636 content=streaming_body(),

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 637why, one step back
637 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 638–650why, one step back
638
639 assert response.status_code == 200640 assert not response.is_closed641642 content = response.read()643644 assert content == b"Hello, world!"645 assert response.content == b"Hello, world!"646 assert response.is_closed647648649@pytest.mark.asyncio650async def test_async_streaming_response():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 651–652why, one step back
651 response = httpx.Response(
652 200,

Support `Response(content=<bytes iterator>)` (#1265)Tom Christiebefore adoption5ee6135

line 653why, one step back
653 content=async_streaming_body(),

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 654why, one step back
654 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 655–666why, one step back
655
656 assert response.status_code == 200657 assert not response.is_closed658659 content = await response.aread()660661 assert content == b"Hello, world!"662 assert response.content == b"Hello, world!"663 assert response.is_closed664665666def test_cannot_read_after_stream_consumed():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 667–668why, one step back
667 response = httpx.Response(
668 200,

Support `Response(content=<bytes iterator>)` (#1265)Tom Christiebefore adoption5ee6135

line 669why, one step back
669 content=streaming_body(),

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 670why, one step back
670 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 671–681why, one step back
671
672 content = b""673 for part in response.iter_bytes():674 content += part675676 with pytest.raises(httpx.StreamConsumed):677 response.read()678679680@pytest.mark.asyncio681async def test_cannot_aread_after_stream_consumed():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 682–683why, one step back
682 response = httpx.Response(
683 200,

Support `Response(content=<bytes iterator>)` (#1265)Tom Christiebefore adoption5ee6135

line 684why, one step back
684 content=async_streaming_body(),

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 685why, one step back
685 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 686–695why, one step back
686
687 content = b""688 async for part in response.aiter_bytes():689 content += part690691 with pytest.raises(httpx.StreamConsumed):692 await response.aread()693694695def test_cannot_read_after_response_closed():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 696–697why, one step back
696 response = httpx.Response(
697 200,

Support `Response(content=<bytes iterator>)` (#1265)Tom Christiebefore adoption5ee6135

line 698why, one step back
698 content=streaming_body(),

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 699why, one step back
699 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 700–701why, one step back
700
701 response.close()

`httpx.ResponseClosed` -> `httpx.StreamClosed` (#1584)Tom Christiebefore adoption9b8f5af

line 702why, one step back
702 with pytest.raises(httpx.StreamClosed):

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 703–707why, one step back
703 response.read()
704705706@pytest.mark.asyncio707async def test_cannot_aread_after_response_closed():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 708–709why, one step back
708 response = httpx.Response(
709 200,

Support `Response(content=<bytes iterator>)` (#1265)Tom Christiebefore adoption5ee6135

line 710why, one step back
710 content=async_streaming_body(),

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 711why, one step back
711 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 712–713why, one step back
712
713 await response.aclose()

`httpx.ResponseClosed` -> `httpx.StreamClosed` (#1584)Tom Christiebefore adoption9b8f5af

line 714why, one step back
714 with pytest.raises(httpx.StreamClosed):

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 715–719why, one step back
715 await response.aread()
716717718@pytest.mark.asyncio719async def test_elapsed_not_available_until_closed():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 720–721why, one step back
720 response = httpx.Response(
721 200,

Support `Response(content=<bytes iterator>)` (#1265)Tom Christiebefore adoption5ee6135

line 722why, one step back
722 content=async_streaming_body(),

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 723why, one step back
723 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 724–729why, one step back
724
725 with pytest.raises(RuntimeError):726 response.elapsed727728729def test_unknown_status_code():

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 730–732why, one step back
730 response = httpx.Response(
731 600,732 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 733–741why, one step back
733 assert response.status_code == 600
734 assert response.reason_phrase == ""735 assert response.text == ""736737738def test_json_with_specified_encoding():739 data = {"greeting": "hello", "recipient": "world"}740 content = json.dumps(data).encode("utf-16")741 headers = {"Content-Type": "application/json, charset=utf-16"}

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 742–746why, one step back
742 response = httpx.Response(
743 200,744 content=content,745 headers=headers,746 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 747–753why, one step back
747 assert response.json() == data
748749750def test_json_with_options():751 data = {"greeting": "hello", "recipient": "world", "amount": 1}752 content = json.dumps(data).encode("utf-16")753 headers = {"Content-Type": "application/json, charset=utf-16"}

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 754–758why, one step back
754 response = httpx.Response(
755 200,756 content=content,757 headers=headers,758 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 759–761why, one step back
759 assert response.json(parse_int=str)["amount"] == "1"
760761

Add `charset_normalizer` detection. (#1791)Tom Christiebefore adoptionacb5e6a

lines 762–775why, one step back
762@pytest.mark.parametrize(
763 "encoding",764 [765 "utf-8",766 "utf-8-sig",767 "utf-16",768 "utf-16-be",769 "utf-16-le",770 "utf-32",771 "utf-32-be",772 "utf-32-le",773 ],774)775def test_json_without_specified_charset(encoding):

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 776why, one step back
776 data = {"greeting": "hello", "recipient": "world"}

Add `charset_normalizer` detection. (#1791)Tom Christiebefore adoptionacb5e6a

line 777why, one step back
777 content = json.dumps(data).encode(encoding)

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 778why, one step back
778 headers = {"Content-Type": "application/json"}

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 779–783why, one step back
779 response = httpx.Response(
780 200,781 content=content,782 headers=headers,783 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 784–786why, one step back
784 assert response.json() == data
785786

Add `charset_normalizer` detection. (#1791)Tom Christiebefore adoptionacb5e6a

lines 787–800why, one step back
787@pytest.mark.parametrize(
788 "encoding",789 [790 "utf-8",791 "utf-8-sig",792 "utf-16",793 "utf-16-be",794 "utf-16-le",795 "utf-32",796 "utf-32-be",797 "utf-32-le",798 ],799)800def test_json_with_specified_charset(encoding):

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 801why, one step back
801 data = {"greeting": "hello", "recipient": "world"}

Add `charset_normalizer` detection. (#1791)Tom Christiebefore adoptionacb5e6a

lines 802–809why, one step back
802 content = json.dumps(data).encode(encoding)
803 headers = {"Content-Type": f"application/json; charset={encoding}"}804 response = httpx.Response(805 200,806 content=content,807 headers=headers,808 )809 assert response.json() == data

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

lines 810–811why, one step back
810
811

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

lines 812–828why, one step back
812@pytest.mark.parametrize(
813 "headers, expected",814 [815 (816 {"Link": "<https://example.com>; rel='preload'"},817 {"preload": {"rel": "preload", "url": "https://example.com"}},818 ),819 (820 {"Link": '</hub>; rel="hub", </resource>; rel="self"'},821 {822 "hub": {"url": "/hub", "rel": "hub"},823 "self": {"url": "/resource", "rel": "self"},824 },825 ),826 ],827)828def test_link_headers(headers, expected):

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 829–833why, one step back
829 response = httpx.Response(
830 200,831 content=None,832 headers=headers,833 )

Cleanup docstring leftover for #1183 (#1201)Joebefore adoptionbd8165a

line 834why, one step back
834 assert response.links == expected

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

lines 835–840why, one step back
835
836837@pytest.mark.parametrize("header_value", (b"deflate", b"gzip", b"br"))838def test_decode_error_with_request(header_value):839 headers = [(b"Content-Encoding", header_value)]840 body = b"test 123"

Use either brotli or brotlicffi. (#1618)Tom Christiebefore adoptiond514312

line 841why, one step back
841 compressed_body = brotli.compress(body)[3:]

Transport API (#1522)Tom Christiebefore adoption1a6e254

line 842why, one step back
842 with pytest.raises(httpx.DecodingError):

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 843–848why, one step back
843 httpx.Response(
844 200,845 headers=headers,846 content=compressed_body,847 )848

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

line 849why, one step back
849 with pytest.raises(httpx.DecodingError):

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 850–855why, one step back
850 httpx.Response(
851 200,852 headers=headers,853 content=compressed_body,854 request=httpx.Request("GET", "https://www.example.org/"),855 )

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

lines 856–861why, one step back
856
857858@pytest.mark.parametrize("header_value", (b"deflate", b"gzip", b"br"))859def test_value_error_without_request(header_value):860 headers = [(b"Content-Encoding", header_value)]861 body = b"test 123"

Use either brotli or brotlicffi. (#1618)Tom Christiebefore adoptiond514312

line 862why, one step back
862 compressed_body = brotli.compress(body)[3:]

Transport API (#1522)Tom Christiebefore adoption1a6e254

line 863why, one step back
863 with pytest.raises(httpx.DecodingError):

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

lines 864–878why, one step back
864 httpx.Response(200, headers=headers, content=compressed_body)
865866867def test_response_with_unset_request():868 response = httpx.Response(200, content=b"Hello, world!")869870 assert response.status_code == 200871 assert response.reason_phrase == "OK"872 assert response.text == "Hello, world!"873 assert not response.is_error874875876def test_set_request_after_init():877 response = httpx.Response(200, content=b"Hello, world!")878

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 879why, one step back
879 response.request = httpx.Request("GET", "https://www.example.org")

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

line 880why, one step back
880

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

lines 881–882why, one step back
881 assert response.request.method == "GET"
882 assert response.request.url == "https://www.example.org"

Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528

lines 883–888why, one step back
883
884885def test_cannot_access_unset_request():886 response = httpx.Response(200, content=b"Hello, world!")887888 with pytest.raises(RuntimeError):

Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4

line 889why, one step back
889 response.request

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

lines 890–896why, one step back
890
891892def test_generator_with_transfer_encoding_header():893 def content():894 yield b"test 123" # pragma: nocover895896 response = httpx.Response(200, content=content())

Support header comparisons with dict or list. (#1326)Musale Martinbefore adoption815ef94

line 897why, one step back
897 assert response.headers == {"Transfer-Encoding": "chunked"}

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

lines 898–905why, one step back
898
899900def test_generator_with_content_length_header():901 def content():902 yield b"test 123" # pragma: nocover903904 headers = {"Content-Length": "8"}905 response = httpx.Response(200, content=content(), headers=headers)

Support header comparisons with dict or list. (#1326)Musale Martinbefore adoption815ef94

line 906why, one step back
906 assert response.headers == {"Content-Length": "8"}

Make Request and Response picklable (#1579)Hannes Ljungbergbefore adoption2d57104

lines 907–944why, one step back
907
908909def test_response_picklable():910 response = httpx.Response(911 200,912 content=b"Hello, world!",913 request=httpx.Request("GET", "https://example.org"),914 )915 pickle_response = pickle.loads(pickle.dumps(response))916 assert pickle_response.is_closed is True917 assert pickle_response.is_stream_consumed is True918 assert pickle_response.next_request is None919 assert pickle_response.stream is not None920 assert pickle_response.content == b"Hello, world!"921 assert pickle_response.status_code == 200922 assert pickle_response.request.url == response.request.url923 assert pickle_response.extensions == {}924 assert pickle_response.history == []925926927@pytest.mark.asyncio928async def test_response_async_streaming_picklable():929 response = httpx.Response(200, content=async_streaming_body())930 pickle_response = pickle.loads(pickle.dumps(response))931 with pytest.raises(httpx.ResponseNotRead):932 pickle_response.content933 with pytest.raises(httpx.StreamClosed):934 await pickle_response.aread()935 assert pickle_response.is_stream_consumed is False936 assert pickle_response.num_bytes_downloaded == 0937 assert pickle_response.headers == {"Transfer-Encoding": "chunked"}938939 response = httpx.Response(200, content=async_streaming_body())940 await response.aread()941 pickle_response = pickle.loads(pickle.dumps(response))942 assert pickle_response.is_stream_consumed is True943 assert pickle_response.content == b"Hello, world!"944 assert pickle_response.num_bytes_downloaded == 13