Skip to content

Commit

Permalink
headers: avoid sending null content-type
Browse files Browse the repository at this point in the history
This commit prevents a null content-type header from being
sent back.

Fixes: #4133
Refs: ed0688c
  • Loading branch information
cjihrig committed Aug 9, 2020
1 parent 5c08509 commit f7e9193
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/headers.js
Expand Up @@ -122,7 +122,7 @@ exports.type = function (request) {

const response = request.response;
const type = response.contentType;
if (type !== response.headers['content-type']) {
if (type !== null && type !== response.headers['content-type']) {
response.type(type);
}
};
Expand Down
10 changes: 10 additions & 0 deletions test/headers.js
Expand Up @@ -523,5 +523,15 @@ describe('Headers', () => {
const res = await server.inject('/?callback=me');
expect(res.payload).to.equal('test');
});

it('does not set content-type by default on 204 response', async () => {

const server = Hapi.server();
server.route({ method: 'GET', path: '/', handler: (request, h) => h.response().code(204) });

const res = await server.inject('/');
expect(res.statusCode).to.equal(204);
expect(res.headers['content-type']).to.equal(undefined);
});
});
});

0 comments on commit f7e9193

Please sign in to comment.