diff --git a/src/message/http/index.ts b/src/message/http/index.ts index ad9fd701..71a6642f 100644 --- a/src/message/http/index.ts +++ b/src/message/http/index.ts @@ -181,8 +181,10 @@ function parseBinary(message: Message, version: string): CloudEvent { } // 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]; } } diff --git a/test/integration/message_test.ts b/test/integration/message_test.ts index 9ddb292d..10f275d1 100644 --- a/test/integration/message_test.ts +++ b/test/integration/message_test.ts @@ -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 = {