Skip to content

Commit 2a78f4c

Browse files
committed
Fix res.sendFile with http2
1 parent 07194ec commit 2a78f4c

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

lib/responseDecorator.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,6 @@ function setMethods(res) {
933933
file.on('error', onerror);
934934
file.on('file', onfile);
935935
file.on('stream', onstream);
936-
onFinished(res, onfinish);
937936

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

951950
// pipe
952951
file.pipe(res);
952+
953+
onFinished(res, onfinish);
953954
}
954955

955956
return res;

test/res.sendFile.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -292,21 +292,18 @@ describe('res', function(){
292292
test.expect(200, cb);
293293
})
294294

295-
// HEAD with http2 does not support response body.
296-
if (!process.env.HTTP2_TEST) {
297-
it('should invoke the callback without error when HEAD', function (done) {
298-
var app = express();
299-
var cb = after(2, done);
300-
301-
app.use(function (req, res) {
302-
res.sendFile(path.resolve(fixtures, 'name.txt'), cb);
303-
});
295+
it('should invoke the callback without error when HEAD', function (done) {
296+
var app = express();
297+
var cb = after(2, done);
304298

305-
request(app)
306-
.head('/')
307-
.expect(200, cb);
299+
app.use(function (req, res) {
300+
res.sendFile(path.resolve(fixtures, 'name.txt'), cb);
308301
});
309-
}
302+
303+
request(app)
304+
.head('/')
305+
.expect(200, cb);
306+
});
310307

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

0 commit comments

Comments
 (0)