fix: HTTP headers for extensions with false values (#493)
* fix: HTTP headers for extensions with false values CloudEvent objects may include extensions that have a defined key and a `false` value. This change ensures that HTTP messages for CloudEvents containing these extension values include the appropriate headers. Signed-off-by: Lance Ball <lball@redhat.com>
This commit is contained in:
parent
ce02e0a1f3
commit
d6f52ca65f
|
@ -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;
|
||||
|
|
|
@ -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> = {
|
||||
|
|
Loading…
Reference in New Issue