Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/message/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ function parseBinary<T>(message: Message, version: string): CloudEvent<T> {
}

// Every unprocessed header can be an extension
// Header names are case-insensitive, so match the prefix and known attributes in any case
for (const header in headers) {
if (header.startsWith(CONSTANTS.EXTENSIONS_PREFIX)) {
const lowerCaseHeader = header.toLowerCase();
if (lowerCaseHeader.startsWith(CONSTANTS.EXTENSIONS_PREFIX) && !parserMap[lowerCaseHeader]) {
eventObj[header.substring(CONSTANTS.EXTENSIONS_PREFIX.length)] = headers[header];
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/integration/message_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,27 @@ describe("HTTP transport", () => {
}).to.throw("invalid attribute name: \"LUNCH\"");
});

it("Includes extensions in binary mode when the header prefix is not lower case", () => {
const message = {
body: `{ "greeting": "hello" }`,
headers: {
"Ce-Id": "1234",
"Ce-Source": "test",
"Ce-Type": "test.event",
"Ce-Specversion": V1,
"Ce-myext": "val",
"CE-otherext": "other",
},
};
const event = HTTP.toEvent(message) as CloudEvent;
expect(event.myext).to.equal("val");
expect(event.otherext).to.equal("other");
expect(event.id).to.equal("1234");
expect(event).not.to.have.property("Id");
expect(event).not.to.have.property("Specversion");
expect(() => event.validate()).not.to.throw();
});

it("Can detect CloudEvent binary Messages with weird versions", () => {
// Now create a message that is an event
const message = {
Expand Down
Loading