Skip to content

Validate content-length fields on bodyless HTTP/2 responses - #1

Merged
Jacob-Met merged 1 commit into
masterfrom
fix/h2-bodyless-content-length-validation-mwjr96c33
Nov 16, 2026
Merged

Jacob-Met merged 1 commit into
masterfrom
fix/h2-bodyless-content-length-validation-mwjr96c33

Conversation

@Jacob-Met

Copy link
Copy Markdown
Owner

HTTP/2 responses to HEAD and with status 204/304 may declare a nonzero representation length, but the existing early return skips validation of the field itself. Malformed values and conflicting duplicates are silently accepted instead of raising ProtocolError.

Parse all content-length fields and preserve the no-body exemption only for the eventual body-length comparison. This leaves valid nonzero declared lengths and rejection of unexpected DATA unchanged. The regression exercises actual HPACK-encoded HEADERS over H2Connection.receive_data for HEAD, 204 and 304.

Verification: six newly added cases fail before the change; after it, 48 targeted cases and 1,761 full-suite tests pass with 100% statement/branch coverage. ruff check src/ and mypy --strict-bytes src tests/typing/strict_bytes.py pass. Linked to upstream bodyless semantics PR python-hyper#1344; this fork PR is staging pending a clean upstream submission.

@Jacob-Met
Jacob-Met merged commit b6aeb4c into master Nov 16, 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