Skip to content

Preserve chunk_start when chunk headers arrive before payload - #210

Open
AryanRG wants to merge 2 commits into
python-hyper:masterfrom
AryanRG:fix/chunk-start-fragmented-header
Open

AryanRG wants to merge 2 commits into
python-hyper:masterfrom
AryanRG:fix/chunk-start-fragmented-header

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 16, 2026 •

Copy link
Copy Markdown

When a chunk header arrives without any payload bytes, ChunkedReader consumes the header and returns NEED_DATA. Its local chunk_start flag is then lost, so the first payload event has chunk_start=False when the bytes arrive later. This affects both requests and responses and violates the documented chunk-boundary contract.

For example, receiving 5\r\n, polling, then receiving hello currently produces Data(..., chunk_start=False, chunk_end=True). Receiving those bytes together produces chunk_start=True.

Keep the start marker in the reader until it emits the first payload event. Subsequent payload events clear it as before. This leaves framing, syntax validation and payload bytes unchanged.

Four regression cases cover both peer roles, ordinary and extended chunk headers delivered byte by byte, repeated polls without payload, a split payload, and a subsequent complete chunk. All four fail on upstream and pass with the fix. Includes a numbered towncrier release note.

Validation on CPython 3.12.15:

  • Full suite: 82 passed (upstream baseline: 78 passed).
  • Changed reader: 100% statement and branch coverage. Overall coverage remains at the upstream baseline of 98.2%.
  • Black 23.3.0, isort 5.12.0, mypy 1.8.0 and git diff --check: passed.
  • Additional validation checked 789 fragmentation schedules, including split chunk footers and trailers.

AI assistance was used to prepare the implementation and regression tests.

Keep the start-of-chunk flag until the first payload event is emitted, so network fragmentation does not lose the documented chunk_start marker. Cover both peer roles, extended headers, repeated polls and split payloads.

AI-assisted-by: OpenAI Codex
@AryanRG
AryanRG marked this pull request as ready for review October 16, 2026 22:37
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.

1 participant