Skip to content

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

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

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

Fixes #314. Supersedes #315 with corrected author/sign-off names; the file tree is identical. GitHub would not reopen the original PR after its branch was recreated.

Type of change: Bug fix

Description:

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

Check Content-Type against the supplied event format before inspecting metadata headers. Match media types case-insensitively and without parameters, including custom formats. Preserve existing fallback behavior. This follows HTTP binding section 3 and section 3.2.3, which permits metadata headers on structured messages.

Correct the 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 dependencies or public APIs change.

Validation (Linux, CPython 3.12.14):

  • All 8 regression cases fail without the fix.
  • Core suite: 350 passed.
  • Full suite: 886 passed, 18 xfailed. Existing Sanic tests required socksio and localhost proxy exclusions in the test environment; project dependencies were not changed.
  • Repository pre-commit checks on the three changed files: passed, including Ruff lint/format and pinned MyPy.
  • Rebuilt branch tree matches the locally tested tree exactly; all three author/sign-off identities match.
  • Other Python/OS combinations were not run locally. Current repository tooling uses uv/pytest rather than tox.

Checklist:

  • Read CONTRIBUTING.md.
  • All commits include matching 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.

Assisted-by: ChatGPT (Codex)
Signed-off-by: Sonam <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 <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 <120879799+BiNKss7@users.noreply.github.com>
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