From ad0c4340b2b3cf8a6204f7fb9e1df140092e23c9 Mon Sep 17 00:00:00 2001 From: Lucas Holmquist Date: Thu, 6 Aug 2020 10:36:53 -0400 Subject: [PATCH] fix: Add Correct Headers to emitted Binary Event (#302) * fix: Binary emitter should add a basic application/json header. fixes #301 Signed-off-by: Lucas Holmquist --- src/transport/http/binary_emitter.ts | 2 +- test/integration/http_emitter_test.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/transport/http/binary_emitter.ts b/src/transport/http/binary_emitter.ts index 1ea8eb0..20f5166 100644 --- a/src/transport/http/binary_emitter.ts +++ b/src/transport/http/binary_emitter.ts @@ -20,7 +20,7 @@ export async function emitBinary(event: CloudEvent, options: TransportOptions): } async function emit(event: CloudEvent, options: TransportOptions, headers: Headers): Promise { - const contentType: Headers = { [CONSTANTS.HEADER_CONTENT_TYPE]: CONSTANTS.DEFAULT_CE_CONTENT_TYPE }; + const contentType: Headers = { [CONSTANTS.HEADER_CONTENT_TYPE]: CONSTANTS.DEFAULT_CONTENT_TYPE }; const config = { ...options, method: "POST", diff --git a/test/integration/http_emitter_test.ts b/test/integration/http_emitter_test.ts index b5f211b..62f0f5c 100644 --- a/test/integration/http_emitter_test.ts +++ b/test/integration/http_emitter_test.ts @@ -4,6 +4,7 @@ import nock from "nock"; import CONSTANTS from "../../src/constants"; const DEFAULT_CE_CONTENT_TYPE = CONSTANTS.DEFAULT_CE_CONTENT_TYPE; +const DEFAULT_CONTENT_TYPE = CONSTANTS.DEFAULT_CONTENT_TYPE; import { CloudEvent, Version, Emitter, Protocol, headersFor } from "../../src"; import { AxiosResponse } from "axios"; @@ -55,6 +56,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => { .send(event) .then((response: AxiosResponse) => { // A binary message will have a ce-id header + expect(response.data["content-type"]).to.equal(DEFAULT_CONTENT_TYPE); expect(response.data[CONSTANTS.CE_HEADERS.ID]).to.equal(event.id); expect(response.data[CONSTANTS.CE_HEADERS.SPEC_VERSION]).to.equal(Version.V1); // A binary message will have a request body for the data @@ -82,6 +84,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => { .then((response: { data: { [k: string]: string } }) => { // A binary message will have a ce-id header expect(response.data.customheader).to.equal("value"); + expect(response.data["content-type"]).to.equal(DEFAULT_CONTENT_TYPE); expect(response.data[CONSTANTS.CE_HEADERS.ID]).to.equal(event.id); expect(response.data[CONSTANTS.CE_HEADERS.SPEC_VERSION]).to.equal(Version.V1); // A binary message will have a request body for the data