Repository navigation
fix(iocp): delimit empty streams and drop Content-Length on 204/304 - #639
Open
edsontmarques wants to merge 2 commits into
Open
edsontmarques wants to merge 2 commits into
edsontmarques wants to merge 2 commits into
Conversation
The IOCP response sent each piece once and ignored how many bytes went out: WriteV (WSASend), the headers, the stream loop and the body sent after the headers. A partial count truncated the response. The stream writer's SendFully looped, but on a failure it left IsConnected true. Every send now goes through SendAll, which repeats until every byte is out; WriteV sends the rest of a partial gather through it. A failed send marks the response, closes the connection through the registry and is never followed by a keep-alive re-arm; IsConnected reads that state. A response without keep-alive is also closed through the registry, so its context no longer stays there until CloseAll. Bytes that arrive after a streamed response (the error response the router builds when the handler raises after SendStream) are no longer appended to it: the connection is closed instead. The low-level sends are replaceable class functions and the registry count is readable, so tests/iocp-http forces partial sends and failures on loopback. seam-only.patch adds just that seam to the previous source for the negative control. tests/iocp-http passes on Delphi 10.2 (CA1 to CA4, plus CA6 as a load measure) and, against the previous source with only the seam applied, fails CA1 to CA4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A stream response emitted Content-Length only when the stream had bytes, so an empty stream on a keep-alive connection went out with neither Content-Length nor Transfer-Encoding and the client could not tell where it ended. A non-empty stream with a Transfer-Encoding set by the handler also got a Content-Length, and every response without a body, 204 included, carried Content-Length: 0. An empty stream now sends Content-Length: 0. A Content-Length or Transfer-Encoding the handler set is kept, compared without case. 204 and 304 carry no Content-Length (RFC 9110, 8.6). tests/iocp-http adds the length check (CA5). CA5 passes on Delphi 10.2 and fails against the previous source with only the seam applied (no Content-Length on the empty stream). Co-Authored-By: Claude Opus 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.
Stacked on #638 (
tests/iocp-httpand the send changes come from there). Until #638 is merged, this PR's diff also shows its commit. The change here is the last commit.Problem
TIocpRawResponsesetContent-Lengthwrongly in three cases:SendStreamResponseemittedContent-Lengthonly when the stream had bytes. On a keep-alive connection, an empty stream (for example aSend(TStream)of an empty list) went out with neitherContent-LengthnorTransfer-Encoding, so the client could not tell where the response ended and waited.Transfer-Encoding: a non-empty stream got aContent-Lengtheven when the handler had setTransfer-Encoding.SendResponseputContent-Length: 0on every response without a body, 204 included. RFC 9110 §8.6 forbidsContent-Lengthon a 204.Change
Content-Length: 0.Content-LengthorTransfer-Encodingthe handler set is kept. Header names are compared without case.Content-Length, on either path.Tests
On Delphi 10.2,
tests/iocp-httpgains CA5:/vazioanswers withContent-Length: 0, read with a 2 s limit, and the same keep-alive connection then serves the next request;/sem-conteudo(204) carries noContent-Length.CA5 passes with this change. Against the previous source with
seam-only.patchit fails, because the empty stream carries noContent-Length. CA1–CA4 and CA6 from #638 still pass.🤖 Generated with Claude Code