sdk-javascript icon indicating copy to clipboard operation
sdk-javascript copied to clipboard

HTTP headers name case for extensions

Open Elvecent opened this issue 2 years ago • 3 comments

It seems that HTTP.toEvent, at least in BINARY mode, looks up extensions in header names starting with "ce-" prefix, however, it looks among original headers supplied in unknown case rather than sanitized headers which are lowercase.

So e. g. "Ce-myext: val" is ignored and doesn't make it into final event's "myext" field.

Elvecent avatar Sep 27 '23 10:09 Elvecent

I'm not following what the bug is here? do you have a reproducible example you could post?

lholmquist avatar Sep 27 '23 13:09 lholmquist

$ node
Welcome to Node.js v20.5.0.
Type ".help" for more information.
> const { HTTP, httpTransport } = await import('cloudevents');
undefined
> const headers = {"Accept":"*/*","Ce-Id":"e2a8d1cb-7ef0-4efb-a24f-608c1715b196","Ce-Myext":"val","Ce-Source":"local","Ce-Specversion":"1.0","Ce-Type":"sometype","Content-Length":"82","Content-Type":"application/json","User-Agent":"curl/7.68.0"}
undefined
> HTTP.toEvent({ headers, body: "body"})
Sanitized headers: {"accept":"*/*","ce-id":"e2a8d1cb-7ef0-4efb-a24f-608c1715b196","ce-myext":"val","ce-source":"local","ce-specversion":"1.0","ce-type":"sometype","content-length":"82","content-type":"application/json","user-agent":"curl/7.68.0"}
Leftover sanitized headers: {"accept":"*/*","ce-myext":"val","content-length":"82","user-agent":"curl/7.68.0"}
{"id":"e2a8d1cb-7ef0-4efb-a24f-608c1715b196","time":"2023-09-28T08:25:48.053Z","type":"sometype","source":"local","specversion":"1.0","datacontenttype":"application/json","data":"body"}

Here, I expect that the resulting object contains value "val" at key "myext". Logs show the value of sanitizedHeaders, and I believe this is exactly where the .startsWith(__1.CONSTANTS.EXTENSIONS_PREFIX) check should happen, but instead it happens in headers, which is the original input headers in mixed case rather than lower case. So the "ce-" prefix check fails, because the actual prefix is "Ce-", and the extension is dropped.

Elvecent avatar Sep 28 '23 08:09 Elvecent

This issue is stale because it has been open 30 days with no activity.

github-actions[bot] avatar Oct 29 '23 00:10 github-actions[bot]