Skip to content

Throw instead of truncating in the HTTP body collect(into:) - #195

Merged
guoye-zhang merged 1 commit into
apple:mainfrom
guoye-zhang:throw-truncate
Oct 14, 2026
Merged

guoye-zhang merged 1 commit into
apple:mainfrom
guoye-zhang:throw-truncate

Conversation

@guoye-zhang

Copy link
Copy Markdown
Collaborator

collect(into:) for HTTP body readers dropped the bytes beyond the buffer's free capacity, and stopped reading once the buffer was full, so a body longer than the buffer looked like a complete body without trailers, and a body exactly as long as the buffer lost its trailers.

It now appends the bytes that fit and throws
AsyncReaderLeftOverElementsError (in an EitherError, as AsyncStreaming's collect(into:) does) for a longer body, and keeps reading a full buffer until the end of the body, so a body that fits exactly returns its trailers.

`collect(into:)` for HTTP body readers dropped the bytes beyond the
buffer's free capacity, and stopped reading once the buffer was full, so a
body longer than the buffer looked like a complete body without trailers,
and a body exactly as long as the buffer lost its trailers.

It now appends the bytes that fit and throws
`AsyncReaderLeftOverElementsError` (in an `EitherError`, as AsyncStreaming's
`collect(into:)` does) for a longer body, and keeps reading a full buffer
until the end of the body, so a body that fits exactly returns its
trailers.
@guoye-zhang guoye-zhang added the 🔨 semver/patch No public API change. label Oct 14, 2026
@guoye-zhang
guoye-zhang merged commit dff8847 into apple:main Oct 14, 2026
21 of 23 checks passed
@guoye-zhang
guoye-zhang deleted the throw-truncate branch October 14, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants