Skip to content
Myr

Merge pull request #21 from yeraydiazdiaz/wait-for-connection-close

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add `raw` method to SyncResponse

authored by Tom Christie · committed by GitHub · parents e1ecb36, 5d552eb · Browse files · 2 files+22 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+22 added−3 removed

  • tests:+14 added−3 removed
  • other:+8 added−0 removed

2 files+22 added−3 removed

modified:httpcore/sync.py+8 added
42 unmodified lines
43 yield self._loop.run_until_complete(inner.__anext__())44 except StopAsyncIteration as exc:45 break4647 def raw(self) -> typing.Iterator[bytes]:48 inner = self._response.raw()49 while True:50 try:51 yield self._loop.run_until_complete(inner.__anext__())52 except StopAsyncIteration as exc:53 break5455 def close(self) -> None:56 return self._loop.run_until_complete(self._response.close())5758
37 unmodified lines
modified:tests/test_sync.py+14 added-3 removed
52 unmodified lines
53def test_stream_iterator(server):54 with httpcore.SyncConnectionPool() as http:55 response = http.request("GET", "http://127.0.0.1:8000/", stream=True)56 assert response.status_code == 20057 content = b""57 body = b""58 for chunk in response.stream():59 content += chunk60 assert content == b"Hello, world!"59 body += chunk60 assert body == b"Hello, world!"616263@threadpool64def test_raw_iterator(server):65 with httpcore.SyncConnectionPool() as http:66 response = http.request("GET", "http://127.0.0.1:8000/", stream=True)67 assert response.status_code == 20068 body = b""69 for chunk in response.raw():70 body += chunk71 assert body == b"Hello, world!"