Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/smithy-http/src/smithy_http/aio/crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,10 @@ def read(self, size: int | None = -1) -> bytes:

if len(self._chunks) == 0:
if self._done:
self.close()
return b""
else:
# When the CRT recieves this, it'll try again
raise BlockingIOError("read")

# We could compile all the chunks here instead of just returning
Expand Down Expand Up @@ -429,4 +431,7 @@ def close(self) -> None:

def end_stream(self) -> None:
"""End the stream, letting any remaining chunks be read before it is closed."""
self._done = True
if len(self._chunks) == 0:
self.close()
else:
self._done = True
6 changes: 6 additions & 0 deletions packages/smithy-http/tests/unit/aio/test_crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def test_done_stream_read() -> None:
assert stream.read() == b""


def test_end_empty_stream() -> None:
stream = BufferableByteStream()
stream.end_stream()
assert stream.read() == b""


def test_stream_read1() -> None:
stream = BufferableByteStream()
stream.write(b"foo")
Expand Down