Skip to content

fix: reserve priority bytes when fragmenting HEADERS - #1353

Open
feiiiiii5 wants to merge 1 commit into
python-hyper:masterfrom
feiiiiii5:feiiiiii5/D235
Open

feiiiiii5 wants to merge 1 commit into
python-hyper:masterfrom
feiiiiii5:feiiiiii5/D235

Conversation

@feiiiiii5

Copy link
Copy Markdown

H2Connection.send_headers(..., priority_weight=16) with a header block larger than the peer's max frame size raises a bare AssertionError (and under python -O would emit an oversized HEADERS frame).

Root cause

_build_headers_frames() slices the encoded header block using the full max frame size, but a priority block adds 5 bytes (4-byte depends_on/exclusive + 1-byte weight) to the first HEADERS payload. PR #1338 documented the same issue for PUSH_PROMISE.

Fix

Added an optional reserved_bytes parameter to H2Stream.send_headers()/_build_headers_frames(); the first fragment is reduced by that amount. H2Connection.send_headers() passes 5 when priority is present. The generic parameter composes with #1338's PUSH_PROMISE reservation and preserves default behaviour.

Verification

  • New parametrized client/server test at MAX_FRAME_SIZE=16384 with a ~50 KB incompressible value. Base-red: AssertionError at _prepare_for_sending (1 failed / 1 passed).
  • With fix: 2 targeted tests passed; full suite 1686 passed, coverage 100% (1918 statements, 466 branches, 0 partial). Both new branches covered.
  • ruff check src/ clean; mypy --strict and --strict-bytes clean.

No h2spec/interop run; python -O not re-run after the fix.

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