Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

response is only finished if socket is detached #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,21 @@ 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 (
msg.finished &&
msg.outputSize === 0 &&
(!socket || socket.writableLength === 0)
Copy link
Author

@ronag ronag Aug 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has landed in node 12 as writableFinished.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: writtableFinished writableFinished.

) || (socket && !socket.writable)
}

if (typeof msg.complete === 'boolean') {
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ describe('isFinished(res)', function () {

it('should be false before response finishes', function (done) {
var server = http.createServer(function (req, res) {
assert.ok(!onFinished.isFinished(res))
res.end()
assert.ok(!onFinished.isFinished(res))
done()
})

Expand Down