Repository navigation
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
NIOHTTPResponseDecompressor and NIOHTTPRequestDecompressor start decoding as soon as the head has
Content-Encoding: gzipordeflate. If the message then ends without any body bytes,decodeLastthrowsExtraDecompressionError.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-Encodingheader of the representation, so a pipeline with the response decompressor reports an error for a valid response. In AsyncHTTPClient this stops a redirect withContent-Encodingand an empty body from being followed.Modifications:
decodeLastonly throwstruncatedDatawhen 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-Encodingand no body no longer fails. A body that starts and is cut off still throwstruncatedData.Two things follow from sharing the decoder between the two handlers: a server-side request with
Content-Encodingand no body is accepted too, and so is a 200 response withContent-Encodingand 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