Repository navigation
Conversation
Normalize Content-Type media types, keep falsy JSON data, and percent-encode ce- header values per the HTTP protocol binding. Signed-off-by: eisen0419 <usetoken0419@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #675
Fixes: #675
Proposed Changes
Align HTTP protocol binding media-type matching, falsy JSON
datahandling, andce-header percent-encoding/decoding with the CloudEvents HTTP Protocol Binding v1.0.2 specification.Summary
Description
Content-Typemedia-type normalization (§3 / §3.1.1 / §3.2.1): Extract the normalizedtype/subtypeessence (case-insensitive, parameters stripped, OWS trimmed) when selecting structured/batch/binary mode and resolving parsers, while still honoring custom entries registered onparserByContentType.application/cloudevents-batch*is classified beforeapplication/cloudevents*, and unregisteredtype/jsonortype/*+jsonmedia types fall back toJSONParser.dataand JSON primitives: Preserve0,false,"", andnullin structured mode instead of dropping falsy values, and parse valid JSON primitives inJSONParser.parsebefore falling back to legacy raw-string quoting.ce-header percent-encoding (§3.1.3.2): Percent-encode stringce-header values on egress (including non-ASCII UTF-8 such as€, spaces,",%, and control characters, preventing NodeERR_INVALID_CHARinhttpTransport) and decode incomingce-headers via OWS trim, optional RFC 7230quoted-stringunescaping, and a single fatal UTF-8 percent-decode pass (ValidationErroron malformed UTF-8).Evidence
HTTP.toEvent({ headers: { "content-type": "application/cloudevents+json; charset=UTF-8" }, body })threwValidationError: Missing required attributes: id, source, type(fell through to binary mode) orUnsupported content type.data: 0,false,"", ornullreturnedevent.data === undefined; binary JSON bodies"0","false","null"stayed strings.emitterFor(httpTransport(...))(new CloudEvent({ ..., subject: "Euro €" }))threwTypeError [ERR_INVALID_CHAR]: Invalid character in header content ["ce-subject"].npm testpasses cleanly (remark,eslint, schema build,tsc, webpack browser bundle, all 7 conformance scenarios / 38 steps, and 281 Mocha tests includingtest/integration/http_binding_interop_test.ts).Merge Danger
Door: Two-way
Self-contained changes in universal HTTP message/header/parser helpers (
src/parsers.ts,src/message/http/index.ts,src/message/http/headers.ts) with no public API signature changes or new dependencies.Blast Radius: Narrow
Scoped to HTTP binding header serialization/parsing and
JSONParsermedia-type lookup; existing customparserByContentTypeoverrides, binaryBufferpassthrough, non-string boolean/integer extension headers, and Kafka/MQTT bindings remain unchanged.