Skip to content

Commit

Permalink
Fix res.sendFile with http2
Browse files Browse the repository at this point in the history
  • Loading branch information
sogaani committed Sep 10, 2018
1 parent 07194ec commit 2a78f4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
3 changes: 2 additions & 1 deletion lib/responseDecorator.js
Expand Up @@ -933,7 +933,6 @@ function setMethods(res) {
file.on('error', onerror);
file.on('file', onfile);
file.on('stream', onstream);
onFinished(res, onfinish);

if (options.headers) {
// set headers on successful transfer
Expand All @@ -950,6 +949,8 @@ function setMethods(res) {

// pipe
file.pipe(res);

onFinished(res, onfinish);
}

return res;
Expand Down
23 changes: 10 additions & 13 deletions test/res.sendFile.js
Expand Up @@ -292,21 +292,18 @@ describe('res', function(){
test.expect(200, cb);
})

// HEAD with http2 does not support response body.
if (!process.env.HTTP2_TEST) {
it('should invoke the callback without error when HEAD', function (done) {
var app = express();
var cb = after(2, done);

app.use(function (req, res) {
res.sendFile(path.resolve(fixtures, 'name.txt'), cb);
});
it('should invoke the callback without error when HEAD', function (done) {
var app = express();
var cb = after(2, done);

request(app)
.head('/')
.expect(200, cb);
app.use(function (req, res) {
res.sendFile(path.resolve(fixtures, 'name.txt'), cb);
});
}

request(app)
.head('/')
.expect(200, cb);
});

it('should invoke the callback without error when 304', function (done) {
var app = express();
Expand Down

0 comments on commit 2a78f4c

Please sign in to comment.