Skip to content

Decouple maxRemainingBodyLength() from live remainingStreamingBytes state#1919

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/change-max-remaining-body-length
Draft

Decouple maxRemainingBodyLength() from live remainingStreamingBytes state#1919
Copilot wants to merge 4 commits intomasterfrom
copilot/change-max-remaining-body-length

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 20, 2026

maxRemainingBodyLength() was reading directly from remainingStreamingBytes, which is mutated during parsing and doesn't reflect a stable "remaining after this chunk" value at the point a dataHandler callback fires.

Changes

  • New member remainingBodyLength: A separate uint64_t remainingBodyLength = 0 field in HttpParser, decoupled from the internal parsing state variable.
  • Set before every dataHandler call (and nowhere else):
    • Content-length: remainingBodyLength = remainingStreamingBytes - emittedChunkSize — bytes left after the current chunk
    • All-remaining / final chunk: remainingBodyLength = 0
    • Chunked (non-final): remainingBodyLength = STATE_IS_CHUNKED — preserves UINT64_MAX semantics in maxRemainingBodyLength()
    • Chunked (final empty chunk) / empty body: remainingBodyLength = 0
  • maxRemainingBodyLength() reads from remainingBodyLength instead of remainingStreamingBytes
uint64_t maxRemainingBodyLength() {
    if (isParsingChunkedEncoding(remainingBodyLength)) {
        return UINT64_MAX;
    }
    return remainingBodyLength;
}

This means callers invoking maxRemainingBodyLength() inside a dataHandler callback now see the remaining body length after the currently emitted chunk is accounted for, not the raw internal streaming counter.


📱 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 16:57
…Length variable set before dataHandler calls

Co-authored-by: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com>
Agent-Logs-Url: https://github.com/uNetworking/uWebSockets/sessions/aa9f6642-4b42-421f-bc6e-a1af47c9fa45
Copilot AI changed the title [WIP] Update maxRemainingBodyLength function to use HttpParser Decouple maxRemainingBodyLength() from live remainingStreamingBytes state Mar 20, 2026
Copilot AI requested a review from uNetworkingAB March 20, 2026 16:58
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