Skip to content

Commit

Permalink
Clone incoming headers
Browse files Browse the repository at this point in the history
  • Loading branch information
kanongil committed Dec 7, 2023
1 parent 9a395d3 commit ed98ebf
Show file tree
Hide file tree
Showing 2 changed files with 12 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 @@ -199,7 +199,7 @@ internals.BoomOutput = class {

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

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

it('clones headers object', () => {

const headers = { custom: ['yes'] };
const err = new Boom.Boom('fail', { statusCode: 400, headers });
err.output.headers.custom.push('more');
err.output.headers.extra = 'added';

expect(err.output.headers).to.equal({ custom: ['yes', 'more'], extra: 'added' });
expect(headers).to.equal({ custom: ['yes'] });
});

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

expect(() => {
Expand Down

0 comments on commit ed98ebf

Please sign in to comment.