Skip to content
Myr

Add `raw` method to SyncResponse

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

authored by Yeray Diaz Diaz · committed by Yeray Diaz Diaz · parent 91a2a1b · Browse files · 2 files+19 added−0 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+19 added−0 removed

  • tests:+11 added−0 removed
  • other:+8 added−0 removed

2 files+19 added−0 removed

modified:httpcore/sync.py+8 added
37 unmodified lines
38 yield self._loop.run_until_complete(inner.__anext__())39 except StopAsyncIteration as exc:40 break4142 def raw(self) -> typing.Iterator[bytes]:43 inner = self._response.raw()44 while True:45 try:46 yield self._loop.run_until_complete(inner.__anext__())47 except StopAsyncIteration as exc:48 break4950 def close(self) -> None:51 return self._loop.run_until_complete(self._response.close())5253
47 unmodified lines
modified:tests/test_sync.py+11 added
55 unmodified lines
56 body = b""57 for chunk in response.stream():58 body += chunk59 assert body == b"Hello, world!"606162@threadpool63def test_raw_iterator(server):64 with httpcore.SyncConnectionPool() as http:65 response = http.request("GET", "http://127.0.0.1:8000/", stream=True)66 assert response.status_code == 20067 body = b""68 for chunk in response.raw():69 body += chunk70 assert body == b"Hello, world!"