Skip to content

fix(v1): handle case-insensitive HTTP headers and Content-Type in converters - #337

Open
xgbtxy wants to merge 2 commits into
cloudevents:mainfrom
xgbtxy:fix/v1-sdk-case-insensitive-http-headers
Open

xgbtxy wants to merge 2 commits into
cloudevents:mainfrom
xgbtxy:fix/v1-sdk-case-insensitive-http-headers

Conversation

@xgbtxy

@xgbtxy xgbtxy commented Dec 2, 2026

Copy link
Copy Markdown

Description

Per RFC 9110 §5.1 / §8.3.1 and the CloudEvents HTTP Protocol Binding specification (§3.1.1 and §3.2.1), HTTP header field names and media types are case-insensitive.

This PR fixes three case-sensitivity mismatches in cloudevents.v1.sdk:

  1. BaseEvent.UnmarshalBinary (src/cloudevents/v1/sdk/event/base.py): checked required_binary_fields - headers.keys() case-sensitively before the loop right below it that normalizes header = header.lower(), causing mixed-case HTTP headers (e.g., Ce-Specversion, Ce-Source, Ce-Type, Ce-Id) to fail with MissingRequiredFields.
  2. has_binary_headers (src/cloudevents/v1/sdk/converters/util.py): checked headers keys case-sensitively, breaking direct BinaryHTTPCloudEventConverter().can_read(headers=...) and JSONHTTPCloudEventConverter().can_read(...) callers passing un-normalized header mappings.
  3. JSONHTTPCloudEventConverter.can_read (src/cloudevents/v1/sdk/converters/structured.py): matched content_type.startswith(self.MIME_TYPE) case-sensitively instead of content_type.lower().startswith(self.MIME_TYPE).

Verification

  • Added regression tests in tests/test_v1_compat/test_base_events.py (v1.Event & v03.Event) and tests/test_v1_compat/test_converters.py (RED -> GREEN).
  • Ran uv run pytest -q (572 passed), uv run ruff check --select I, uv run ruff check, and uv run ruff format --check.

…verters

Signed-off-by: Yan Chen <yan8925298@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 01:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@EmiRZx EmiRZx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested locally, all tests pass. from_http and FromRequest already lowercase header names, so the visible change there is a mixed-case structured Content-Type that comes with ce- headers. main reads it as binary, this branch as structured, same as the lowercase form. the header name changes fix direct calls to can_read and UnmarshalBinary. nit, startswith still matches application/cloudevents+jsonl. comparing the media type before ; would avoid that, as cloudevents/sdk-rust#316 does.

…verter

Signed-off-by: Yan Chen <yan8925298@gmail.com>
@xgbtxy

xgbtxy commented Dec 2, 2026

Copy link
Copy Markdown
Author

Thanks for the catch, @EmiRZx — updated JSONHTTPCloudEventConverter.can_read to compare the normalized media type before ; and added +jsonl negative tests in 5a913ca.

@EmiRZx EmiRZx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked 5a913ca. application/cloudevents+jsonl with ce- headers is now read as binary. parameters and mixed case still match, and the tests pass.

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.

4 participants