Skip to content
Myr

Fix for stream uploads that subclass SyncByteStream/AsyncByteStream (#2016)

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

authored by Tom Christie · committed by GitHub · parent 99ba25c · Browse files · 2 files+18 added−2 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+18 added−2 removed

  • tests:+12 added−0 removed
  • other:+6 added−2 removed

2 files+18 added−2 removed

modified:httpx/_content.py+6 added-2 removed
48 unmodified lines
49 if self._is_stream_consumed and self._is_generator:50 raise StreamConsumed()5152 self._is_stream_consumed = True53 if hasattr(self._stream, "read"):53 if hasattr(self._stream, "read") and not isinstance(54 self._stream, SyncByteStream55 ):56 # File-like interfaces should use 'read' directly.57 chunk = self._stream.read(self.CHUNK_SIZE) # type: ignore58 while chunk:59 yield chunk
16 unmodified lines
76 if self._is_stream_consumed and self._is_generator:77 raise StreamConsumed()7879 self._is_stream_consumed = True78 if hasattr(self._stream, "aread"):80 if hasattr(self._stream, "aread") and not isinstance(81 self._stream, AsyncByteStream82 ):83 # File-like interfaces should use 'aread' directly.84 chunk = await self._stream.aread(self.CHUNK_SIZE) # type: ignore85 while chunk:86 yield chunk
151 unmodified lines
modified:tests/test_api.py+12 added
26 unmodified lines
27 assert response.status_code == 20028 assert response.reason_phrase == "OK"293031def test_post_byte_stream(server):32 class Data(httpx.SyncByteStream):33 def __iter__(self):34 yield b"Hello"35 yield b", "36 yield b"world!"3738 response = httpx.post(server.url, content=Data())39 assert response.status_code == 20040 assert response.reason_phrase == "OK"414243def test_options(server):44 response = httpx.options(server.url)45 assert response.status_code == 20046 assert response.reason_phrase == "OK"
39 unmodified lines