Skip to content

Don't throw truncatedData for a message that has no body - #335

Open
o-nnerb wants to merge 1 commit into
apple:mainfrom
request-dl:decompressor-no-body
Open

o-nnerb wants to merge 1 commit into
apple:mainfrom
request-dl:decompressor-no-body

Conversation

@o-nnerb

@o-nnerb o-nnerb commented Nov 19, 2026

Copy link
Copy Markdown

Motivation:

NIOHTTPResponseDecompressor and NIOHTTPRequestDecompressor start decoding as soon as the head has Content-Encoding: gzip or deflate. If the message then ends without any body bytes, decodeLast throws ExtraDecompressionError.truncatedData, because no compressed stream was ever completed.

A response to a HEAD request and a 304 normally have no body but keep the Content-Encoding header of the representation, so a pipeline with the response decompressor reports an error for a valid response. In AsyncHTTPClient this stops a redirect with Content-Encoding and an empty body from being followed.

Modifications:

decodeLast only throws truncatedData when some compressed bytes were consumed. A message with no body bytes finishes normally, and its head and end are forwarded as they are.

New tests cover bodiless responses (301, 302, 307, 204, 304 and 200, with gzip and deflate), a bodiless response followed by a normal compressed one on the same channel, a bodiless request, and truncated gzip bodies for both handlers, which still throw. The new tests fail without the change in HTTPDecompressor.swift.

Result:

A message with Content-Encoding and no body no longer fails. A body that starts and is cut off still throws truncatedData.

Two things follow from sharing the decoder between the two handlers: a server-side request with Content-Encoding and no body is accepted too, and so is a 200 response with Content-Encoding and an empty body. I'm not sure that second case is wanted, and I can narrow the check if you'd rather not accept it.

🤖 Generated with Claude Code

The decompressor is created as soon as the head says gzip or deflate. If
the message then ends without a single body byte, which is normal for
HEAD responses and 304s, decodeLast threw truncatedData.

Only throw it when some compressed bytes arrived and the stream did not
finish.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant