Repository navigation
fakeserver: CompressShape shapes the COMPRESS DEFLATE output stream - #15
Merged
Merged
Conversation
Flush kind (sync, zlib-style partial flush like INN's nnrpd, final block with trailing bytes), compressed bytes split across socket writes (offsets from the start or end, so also inside the 00 00 FF FF marker), an empty flush or pipelined payload in the same socket write as the 206. Option on StoreOptions, PeerOptions, Step and Conn.StartCompressShaped; the zero value is the old behaviour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Arm the 206 tail only when compression will start, keep the caller's write deadline across a split gap, record writes before they happen in the test recorder, terminate the partial-flush test stream correctly, document the unsent bits and the tail in fault offsets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Shapes the fake server's COMPRESS DEFLATE (RFC 8054) output stream for client tests (survey item B6; go-pugleaf asked for split writes and the empty flush with the 206, partial flush as nice-to-have).
API
CompressShape(new fieldCompressShapeonStoreOptions,PeerOptionsandStep;Conn.StartCompressShaped(shape)for a Handler that writes its own 206):FlushFlushSync(default);FlushPartial: zlib's Z_PARTIAL_FLUSH like INN's nnrpd (empty fixed-Huffman block, no00 00 FF FF, the last 0-7 bits unsent);FlushFinish: the first write after the 206 ends the stream (final block), later writes are plainSplitSplittype applied to the compressed bytes of each write:At(a negative offset counts from the end, so -1..-3 cut inside the sync marker),Size,Gap(bounded by the Deadline, via the conn's Sleep)EmptyFlushWith206With206 []byteTestCliCompressPipelinedAfter206hand-builds)AfterEnd []byteFlushFinish: bytes after the final block, in the same writeBehaviour changes
None: the zero value takes the old path (one default-level flate writer, sync flush, one socket write per write).
Design
FlushPartialuses a ~40-line bit writer with fixed-Huffman literal blocks (no matches; output is larger, correctness is what matters). zlib >= 1.2.5.2 semantics: data block, then one empty static block (3 header bits + 7-bit EOB), only whole bytes sent.internal/inflate, and one unit test completes the stream (pad + final stored block) to check it with compress/flate's reader, including all 256 literal values.WriteinwriteKind(the encoder is created there and handed tostartCompress, so bit state continues). That works in the kit's handlers only; a custom Handler that writes its own 206 cannot useEmptyFlushWith206/With206, documented.Skipped
Tests
New
fakeserver/compressshape_test.go: default stays one write per reply; exact socket pieces (recorded writes plusreadPieceswith a lower-bound timing check, never read boundaries); inside-the-marker cuts; byte-wise delivery to compress/flate's reader; empty flush with the 206 (sync and partial, recorded as one write, nothing after the 206 without the option);With206; partial flush (prompt delivery, no marker, encoder vs compress/flate); finish with and without trailing bytes; Peer and Script step;StartCompressShaped.go vet ./...,go test -race ./...,go test -race -count=10 -run Compress ./fakeservergreen.🤖 Generated with Claude Code