Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP headers name case for extensions #566

Open
Elvecent opened this issue Sep 27, 2023 · 3 comments
Open

HTTP headers name case for extensions #566

Elvecent opened this issue Sep 27, 2023 · 3 comments

Comments

@Elvecent
Copy link

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.

@lholmquist
Copy link
Contributor

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

@Elvecent
Copy link
Author

$ 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.

@github-actions
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants