Skip to content

Decrement remainingStreamingBytes before dataHandler calls; simplify isLast check#1918

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/properly-decrement-streaming-bytes
Draft

Decrement remainingStreamingBytes before dataHandler calls; simplify isLast check#1918
Copilot wants to merge 4 commits intomasterfrom
copilot/properly-decrement-streaming-bytes

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 20, 2026

maxRemainingBodyLength() inside onData callbacks returned the byte count including the current chunk, breaking the invariant isLast == (maxRemainingBodyLength() == 0) for both content-length and chunked transfers.

Changes

  • Content-length: Decrement remainingStreamingBytes before calling dataHandler (was after), then pass remainingStreamingBytes == 0 directly as isLast — no local variable needed.

    // Before
    dataHandler(user, std::string_view(data, emittable), emittable == remainingStreamingBytes);
    remainingStreamingBytes -= emittable;
    
    // After
    remainingStreamingBytes -= emittable;
    dataHandler(user, std::string_view(data, emittable), remainingStreamingBytes == 0);
  • Chunked encoding: For the terminal empty chunk, temporarily set remainingStreamingBytes = 0 before calling dataHandler, then restore the saved state so ChunkIterator can still drop the trailing CRLF on its next step.

Applied consistently across all three call sites: fenceAndConsumePostPadded, the direct path in consumePostPadded, and the fallback path in consumePostPadded.


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI and others added 2 commits March 20, 2026 01:45
- For content-length: decrement remainingStreamingBytes before calling
  dataHandler so maxRemainingBodyLength() within onData excludes current chunk
- For chunked encoding: set remainingStreamingBytes=0 before calling
  dataHandler with the last (empty) chunk, restore state after so
  ChunkIterator can properly drop trailing CRLF bytes

Ensures isLast == (maxRemainingBodyLength() == 0) for both transfer modes.

Co-authored-by: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com>
Co-authored-by: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix remainingStreamingBytes decrement before dataHandler calls Decrement remainingStreamingBytes before dataHandler calls Mar 20, 2026
Copilot AI requested a review from uNetworkingAB March 20, 2026 01:46
Copilot AI changed the title Decrement remainingStreamingBytes before dataHandler calls Decrement remainingStreamingBytes before dataHandler calls; simplify isLast check Mar 20, 2026
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.

2 participants