Skip to content

Commit e0b27bf

Browse files
lholmquistlance
authored andcommitted
src: allow custom headers (#1)
Signed-off-by: Lucas Holmquist <[email protected]>
1 parent b372699 commit e0b27bf

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/transport/http/binary_emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function emit(event: CloudEvent, options: Options, headers: Headers): Prom
1818
const config = {
1919
...options,
2020
method: "POST",
21-
headers: { ...contentType, ...headers },
21+
headers: { ...contentType, ...headers, ...options.headers as Headers},
2222
data: asData(event.data, event.datacontenttype as string)
2323
};
2424
return axios.request(config as AxiosRequestConfig);

test-ts/http_emitter_test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
6868
expect(headers[v1Headers.BINARY_HEADERS.TIME]).to.equal(event.time);
6969
});
7070

71+
it("Sends a binary CloudEvent with Custom Headers", () => {
72+
emitter.send(event, { headers: { customheader: "value" } }).then((response: { data: { [k: string]: string } }) => {
73+
// A binary message will have a ce-id header
74+
expect(response.data.customheader).to.equal("value");
75+
expect(response.data[v1Headers.BINARY_HEADERS.ID]).to.equal(event.id);
76+
expect(response.data[v1Headers.BINARY_HEADERS.SPEC_VERSION]).to.equal(Version.V1);
77+
// A binary message will have a request body for the data
78+
expect(response.data.lunchBreak).to.equal(data.lunchBreak);
79+
}).catch(expect.fail);
80+
});
81+
7182
it("Sends a structured 1.0 CloudEvent if specified", () => {
7283
emitter.send(event, { protocol: Protocol.HTTPStructured })
7384
.then((response: { data: { [k: string]: string | {}, data: { lunchBreak: string } } }) => {

0 commit comments

Comments
 (0)