diff options
author | Robert Nagy <ronagy@icloud.com> | 2018-04-23 14:42:19 -0200 |
---|---|---|
committer | Trivikram Kamat <16024985+trivikr@users.noreply.github.com> | 2018-05-13 22:54:34 -0700 |
commit | ffb503be5f07a26d73a2b3b59955636452948ba7 (patch) | |
tree | d81dca8a0e19a4a1a277607007aa3ea140fbe825 /lib/_http_client.js | |
parent | fcf2e4207edab9b85f8435b89489dd6148a7637e (diff) | |
download | android-node-v8-ffb503be5f07a26d73a2b3b59955636452948ba7.tar.gz android-node-v8-ffb503be5f07a26d73a2b3b59955636452948ba7.tar.bz2 android-node-v8-ffb503be5f07a26d73a2b3b59955636452948ba7.zip |
http: fix client response close & aborted
Fixes: https://github.com/nodejs/node/issues/20102
Fixes: https://github.com/nodejs/node/issues/20101
Fixes: https://github.com/nodejs/node/issues/1735
- Response should always emit close.
- Response should always emit aborted if aborted.
- Response should always emit close after request has emitted close.
PR-URL: https://github.com/nodejs/node/pull/20075
Fixes: https://github.com/nodejs/node/issues/17352
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib/_http_client.js')
-rw-r--r-- | lib/_http_client.js | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/lib/_http_client.js b/lib/_http_client.js index 1985c617be..92c2954d0c 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -340,26 +340,33 @@ function socketCloseListener() { // NOTE: It's important to get parser here, because it could be freed by // the `socketOnData`. - var parser = socket.parser; - if (req.res && req.res.readable) { + const parser = socket.parser; + const res = req.res; + if (res) { // Socket closed before we emitted 'end' below. - if (!req.res.complete) { - req.res.aborted = true; - req.res.emit('aborted'); + if (!res.complete) { + res.aborted = true; + res.emit('aborted'); } - var res = req.res; - res.on('end', function() { + req.emit('close'); + if (res.readable) { + res.on('end', function() { + this.emit('close'); + }); + res.push(null); + } else { res.emit('close'); - }); - res.push(null); - } else if (!req.res && !req.socket._hadError) { - // This socket error fired before we started to - // receive a response. The error needs to - // fire on the request. - req.socket._hadError = true; - req.emit('error', createHangUpError()); + } + } else { + if (!req.socket._hadError) { + // This socket error fired before we started to + // receive a response. The error needs to + // fire on the request. + req.socket._hadError = true; + req.emit('error', createHangUpError()); + } + req.emit('close'); } - req.emit('close'); // Too bad. That output wasn't getting written. // This is pretty terrible that it doesn't raise an error. |