Repository navigation
Conversation
The current implementation copies binary object and values into the header map as-is. This would produce incorrectly encoded HTTP headers, and the current behaviour relies on object coercion in axios. Instead we are explicitly serializing incompatible types to String. The CloudEvents type system has no object type, so accepting objects as extension values is an SDK convenience rather than spec behavior. In the long run, we should pivot to a spec compliant option, and throw an error for this case, and instead as the client to correctly set headers. Split from cloudevents#646. Signed-off-by: Shiva <shiv@shiv.me> Co-authored-by: Kevin Mathew Sunny <tokevins@protonmail.com>
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.
Written for: the cloudevents/sdk-javascript maintainers and the #646 participants (duglin, kings1ay3r, blackakula, fhirter).
Summary
Lands the one behavioral fix from #646 on its own: object-valued extension
attributes are now serialized as JSON in binary-mode HTTP headers instead of
reaching the wire as
[object Object].Part of #646. Does not close it; see "What remains" below.
Problem
headersFor()copied extension values into the header map as-is. Anobject-valued extension therefore reached the HTTP client as an object, and
Node's
httpmodule, axios, got and superagent all coerce header valueswith
String():ce-traceinfo: [object Object]
The emitter test had been working around this since #661 by stringifying in
test code, which is a sign the fix belonged in the SDK.
Change
headersFor()serializes objects withJSON.stringify(). Strings,booleans and numbers pass through unchanged. Two lines.
through
HTTP.toEvent()delivers that string to the receiver.accepting objects as extension values is an SDK convenience, not spec
behavior. The README gains an "Extension Attributes" section, the
CloudEventV1extension JSDoc and a comment at the call site say thesame, and all three recommend encoding the value as a string yourself.
Compatibility
[object Object].HTTP.binary(event).headersdirectly, orround-trip through
HTTP.toEvent()without a network, now get a JSONstring where they used to get the object. This matches the declared
Headerstype, which has always said values are strings.non-conformant and discouraged. A deprecation warning with removal in v11
is planned as a follow-up rather than bundled here.
What remains from #646
Already on main via #661, so dropped from this series: every dependency
bump including uuid 11 (closes the GHSA in #647), the
@types/uuidand@types/cucumberremovals, theValidationErrorrewrite, and theJSONParser.parsereturn type. Theas string | Record<...>cast is ano-op on current main and was dropped too.
Still to come, each as its own small PR, authored by @kings1ay3r with his
sign-off preserved:
DateParserearly return, using @blackakula'sisNaNsuggestionsteps.tsguard on the time comparisonvalidation.tsThe last of those will carry
Closes #646.Credit
The fix is @kings1ay3r's idea from #646, reshaped to the smallest change
and given tests and docs. Recorded as
Co-authored-byon the commit.