diff --git a/index.js b/index.js index a6724cf..73a2495 100644 --- a/index.js +++ b/index.js @@ -64,10 +64,17 @@ function onFinished (msg, listener) { function isFinished (msg) { var socket = msg.socket + var stream = msg.stream + + if (stream && typeof stream.closed === 'boolean') { + // Http2ServerRequest + // Http2ServerResponse + return stream.closed + } if (typeof msg.finished === 'boolean') { // OutgoingMessage - return Boolean(msg.finished || (socket && !socket.writable)) + return Boolean((!socket && msg.finished && msg.outputSize === 0) || (socket && !socket.writable)) } if (typeof msg.complete === 'boolean') {