Skip to content

Fix remainingStreamingBytes timing: set before requestHandler, decrement before dataHandler#1916

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-remaining-streaming-bytes-update
Draft

Fix remainingStreamingBytes timing: set before requestHandler, decrement before dataHandler#1916
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-remaining-streaming-bytes-update

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

maxRemainingBodyLength() relied on remainingStreamingBytes internally, but the value was set after requestHandler and decremented after dataHandler, making it meaningless when called from either callback.

Changes

  • Set remainingStreamingBytes before requestHandler: all three cases (chunked → STATE_IS_CHUNKED, content-length → parsed value, no body → explicit 0) are now resolved prior to the request handler being invoked
  • Decrement remainingStreamingBytes before dataHandler: all four content-length streaming call sites in fenceAndConsumePostPadded and consumePostPadded (including post-fallback paths) now update the counter first, compute fin from the pre-decrement value, then invoke dataHandler
// content-length path — before:
dataHandler(user, std::string_view(data, emittable), emittable == remainingStreamingBytes);
remainingStreamingBytes -= emittable;

// after:
bool fin = (emittable == remainingStreamingBytes);
remainingStreamingBytes -= emittable;
dataHandler(user, std::string_view(data, emittable), fin);

Chunked-encoding paths are unaffected — ChunkIterator maintains remainingStreamingBytes internally.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits March 13, 2026 16:32
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 when remainingStreamingBytes is set for GET requests Fix remainingStreamingBytes set before requestHandler Mar 13, 2026
Copilot AI requested a review from uNetworkingAB March 13, 2026 16:33
Co-authored-by: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com>
Copilot AI changed the title Fix remainingStreamingBytes set before requestHandler Fix remainingStreamingBytes timing: set before requestHandler, decrement before dataHandler Mar 13, 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