Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: HTTP headers for extensions with false values #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 14, 2022
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
2 changes: 1 addition & 1 deletion src/message/http/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function headersFor<T>(event: CloudEventV1<T>): Headers {
// iterate over the event properties - generate a header for each
Object.getOwnPropertyNames(event).forEach((property) => {
const value = event[property];
if (value) {
if (value !== undefined) {
const map: MappedParser | undefined = headerMap[property] as MappedParser;
if (map) {
headers[map.name] = map.parser.parse(value as string) as string;
Expand Down
20 changes: 20 additions & 0 deletions test/integration/message_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ const imageData = new Uint32Array(fs.readFileSync(path.join(process.cwd(), "test
const image_base64 = asBase64(imageData);

describe("HTTP transport", () => {

it("Includes extensions in binary mode when type is 'boolean' with a false value", () => {
const evt = new CloudEvent({ source: "test", type: "test", extboolean: false });
expect(evt.hasOwnProperty("extboolean")).to.equal(true);
expect(evt["extboolean"]).to.equal(false);
const message = HTTP.binary(evt);
expect(message.headers.hasOwnProperty("ce-extboolean")).to.equal(true);
expect(message.headers["ce-extboolean"]).to.equal(false);
});

it("Includes extensions in structured when type is 'boolean' with a false value", () => {
const evt = new CloudEvent({ source: "test", type: "test", extboolean: false });
expect(evt.hasOwnProperty("extboolean")).to.equal(true);
expect(evt["extboolean"]).to.equal(false);
const message = HTTP.structured(evt);
const body = JSON.parse(message.body as string);
expect(body.hasOwnProperty("extboolean")).to.equal(true);
expect(body.extboolean).to.equal(false);
});

it("Handles events with no content-type and no datacontenttype", () => {
const body = "{Something[Not:valid}JSON";
const message: Message<undefined> = {
Expand Down