From 5562a32d8823b6b3ddbf667249c3daa045f15133 Mon Sep 17 00:00:00 2001 From: Lucas Holmquist Date: Mon, 15 Jun 2020 11:57:36 -0400 Subject: [PATCH 1/2] fix: correct the spread order for http_emitter options fixes: #223 Signed-off-by: Lucas Holmquist --- src/lib/bindings/http/emitter_binary.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/bindings/http/emitter_binary.js b/src/lib/bindings/http/emitter_binary.js index ab9288ce..a9d03b29 100644 --- a/src/lib/bindings/http/emitter_binary.js +++ b/src/lib/bindings/http/emitter_binary.js @@ -53,7 +53,7 @@ class BinaryHTTPEmitter { * @returns {Promise} Promise with an eventual response from the receiver */ async emit(options, cloudevent) { - const config = { ...options, ...defaults }; + const config = { ...defaults, ...options }; const headers = config[HEADERS]; this.headerParserMap.forEach((parser, getterName) => { From 8619cd5a39f0153649b406817ee88b299a4fc39c Mon Sep 17 00:00:00 2001 From: Lucas Holmquist Date: Mon, 15 Jun 2020 12:30:35 -0400 Subject: [PATCH 2/2] squash: add test Signed-off-by: Lucas Holmquist --- test-ts/http_emitter_test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test-ts/http_emitter_test.ts b/test-ts/http_emitter_test.ts index 273ed689..4ff94de0 100644 --- a/test-ts/http_emitter_test.ts +++ b/test-ts/http_emitter_test.ts @@ -64,6 +64,17 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => { }).catch(expect.fail); }); + it("Sends a binary CloudEvent with Custom Headers", () => { + emitter.send(event, { headers: { customheader: "value" } }).then((response: { data: { [k: string]: string } }) => { + // A binary message will have a ce-id header + expect(response.data.headers.customheader).to.equal("value"); + expect(response.data[BINARY_HEADERS_1.ID]).to.equal(event.id); + expect(response.data[BINARY_HEADERS_1.SPEC_VERSION]).to.equal(SPEC_V1); + // A binary message will have a request body for the data + expect(response.data.lunchBreak).to.equal(data.lunchBreak); + }).catch(expect.fail); + }); + it("Provides the HTTP headers for a binary event", () => { const headers = HTTPEmitter.headers(event); expect(headers[BINARY_HEADERS_1.TYPE]).to.equal(event.type);