Skip to content

fix(http): prioritize structured Content-Type over metadata headers - #315

Closed
BiNKss7 wants to merge 3 commits into
cloudevents:mainfrom
BiNKss7:fix/http-structured-content-type
Closed

BiNKss7 wants to merge 3 commits into
cloudevents:mainfrom
BiNKss7:fix/http-structured-content-type

Conversation

@BiNKss7

@BiNKss7 BiNKss7 commented Nov 16, 2026 •

Copy link
Copy Markdown

Related Issue: Fixes #314

Type of change: Bug fix

Description:

The core HTTP decoder currently selects binary mode whenever it sees any ce-* header. A structured request with redundant metadata headers therefore uses the header attributes and treats its entire envelope as data; a lone ce-subject header can instead make a valid structured event fail validation.

Check the request Content-Type against the supplied format media type before inspecting metadata headers. Matching ignores media type casing and parameters, and works with custom formats. Existing fallback handling is preserved. This follows HTTP binding section 3 and section 3.2.3, which permits metadata headers on structured messages.

Correct the existing mixed-headers test that asserted binary precedence, and cover explicit/auto-detected factories, casing, parameters, partial metadata and a custom format. Include a changelog entry. No dependency or public API changes.

Validation (Linux, CPython 3.12.14):

  • All 8 regression cases fail without the fix.
  • Core suite: 350 passed.
  • Full suite: 886 passed, 18 xfailed. The test environment needed socksio and localhost proxy exclusions for existing Sanic integration tests; project dependencies were not changed.
  • Repository pre-commit checks on all three changed files: passed, including Ruff lint/format and pinned MyPy.
  • The uploaded branch tree was compared with the locally tested tree and matches exactly.
  • Other Python/OS combinations were not run locally. Current repository tooling uses uv/pytest, not tox.

Checklist:

  • Read CONTRIBUTING.md.
  • All commits include Signed-off-by trailers.
  • Regression tests and changelog included.
  • Local tests and repository pre-commit checks pass.
  • Ready for review.

Honor the supplied event format before checking ce- headers, as required by the HTTP binding sections 3 and 3.2.3. Regression tests and changelog follow on this branch before submitting a PR.

Assisted-by: ChatGPT (Codex)
Signed-off-by: Sonam Sherpa <120879799+BiNKss7@users.noreply.github.com>
Cover redundant metadata headers, Content-Type casing and parameters, explicit and inferred factories, partial metadata, and custom formats. All eight regression cases fail without the source fix.

Assisted-by: ChatGPT (Codex)
Signed-off-by: Sonam Sherpa <120879799+BiNKss7@users.noreply.github.com>
Document the corrected precedence of structured Content-Type over redundant metadata headers.

Assisted-by: ChatGPT (Codex)
Signed-off-by: Sonam Sherpa <120879799+BiNKss7@users.noreply.github.com>
@BiNKss7 BiNKss7 closed this Nov 16, 2026
@BiNKss7
BiNKss7 deleted the fix/http-structured-content-type branch November 16, 2026 01:36
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.

Core HTTP decoder ignores structured Content-Type when metadata headers are present

1 participant