Skip to content

Commit

Permalink
fixup! http2: allow passing FileHandle to respondWithFD
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Oct 8, 2019
1 parent e9d05d2 commit 3c91a7e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2524,13 +2524,10 @@ class ServerHttp2Stream extends Http2Stream {
this[kState].flags |= STREAM_FLAGS_HAS_TRAILERS;
}

if (typeof fd !== 'number' &&
!(fd instanceof fsPromisesInternal.FileHandle)) {
throw new ERR_INVALID_ARG_TYPE('fd', ['number', 'FileHandle'], fd);
}

if (typeof fd !== 'number') // FileHandle
if (fd instanceof fsPromisesInternal.FileHandle)
fd = fd.fd;
else if (typeof fd !== 'number')
throw new ERR_INVALID_ARG_TYPE('fd', ['number', 'FileHandle'], fd);

debugStreamObj(this, 'initiating response from fd');
this[kUpdateTimer]();
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http2-respond-file-filehandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fs.promises.open(fname, 'r').then(common.mustCall((fileHandle) => {
});
});
server.on('close', common.mustCall(() => fileHandle.close()));
server.listen(0, () => {
server.listen(0, common.mustCall(() => {

const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
Expand All @@ -43,5 +43,5 @@ fs.promises.open(fname, 'r').then(common.mustCall((fileHandle) => {
server.close();
}));
req.end();
});
}));
}));

0 comments on commit 3c91a7e

Please sign in to comment.