Skip to content

Commit

Permalink
Ignore all non-object headers option
Browse files Browse the repository at this point in the history
  • Loading branch information
kanongil committed Nov 1, 2024
1 parent b2102b1 commit 46c282c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ internals.BoomOutput = class {
constructor(statusCode, headers) {

this.statusCode = statusCode;
this.headers = headers ? Hoek.clone(headers, { prototype: false, symbols: false }) : {};
this.headers = typeof headers === 'object' ? Hoek.clone(headers, { prototype: false, symbols: false }) : {};
}
};

Expand Down
8 changes: 8 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ describe('Boom', () => {
expect(headers).to.equal({ custom: ['yes'] });
});

it('ignores non-object headers option', () => {

const err = new Boom.Boom('fail', { statusCode: 400, headers: true });
expect(err.output.payload.message).to.equal('fail');
expect(err.output.statusCode).to.equal(400);
expect(err.output.headers).to.equal({});
});

it('throws when statusCode is invalid', () => {

expect(() => {
Expand Down

0 comments on commit 46c282c

Please sign in to comment.