Skip to content

Commit

Permalink
Retail etag on head. Closes #1772
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Jul 10, 2014
1 parent 740afa9 commit 7dc078b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/response/index.js
Expand Up @@ -90,8 +90,11 @@ internals.marshall = function (request, next) {

response._payload = new internals.Empty();
delete response.headers['content-length'];
delete response.headers.etag;
delete response.headers['last-modified'];

if (response.statusCode === 304) {
delete response.headers.etag;
delete response.headers['last-modified'];
}

return internals.headers(request, next);
}
Expand Down
17 changes: 17 additions & 0 deletions test/response.js
Expand Up @@ -1646,6 +1646,23 @@ describe('Response', function () {
});
});

it('retains etag header on head', function (done) {

var server = new Hapi.Server();
server.route({ method: 'GET', path: '/file', handler: { file: __dirname + '/../package.json' } });

server.inject('/file', function (res1) {

server.inject({ method: 'HEAD', url: '/file' }, function (res2) {

expect(res2.statusCode).to.equal(200);
expect(res2.headers).to.have.property('etag');
expect(res2.headers).to.have.property('last-modified');
done();
});
});
});

it('returns 200 if if-modified-since is invalid', function (done) {

var server = new Hapi.Server();
Expand Down

0 comments on commit 7dc078b

Please sign in to comment.