diff options
author | Rich Trott <rtrott@gmail.com> | 2019-07-15 07:57:40 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-07-15 08:40:19 -0700 |
commit | 0796f0e268f4eef6c13280c9df679131db5d6b86 (patch) | |
tree | fd353caf041ce9cf22b1e4fd97539b2f4f678be8 | |
parent | c3caf21bd35359fe8b0470a65775ade5979890f7 (diff) | |
download | android-node-v8-0796f0e268f4eef6c13280c9df679131db5d6b86.tar.gz android-node-v8-0796f0e268f4eef6c13280c9df679131db5d6b86.tar.bz2 android-node-v8-0796f0e268f4eef6c13280c9df679131db5d6b86.zip |
Revert "http: fix test where aborted should not be emitted"
This reverts commit 461bf36d701f3f7c669e2d916d5a5bc17fc447bf.
PR-URL: https://github.com/nodejs/node/pull/28699
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
-rw-r--r-- | doc/api/http.md | 5 | ||||
-rw-r--r-- | lib/_http_client.js | 16 | ||||
-rw-r--r-- | test/parallel/test-http-client-aborted.js | 23 | ||||
-rw-r--r-- | test/parallel/test-http-client-no-error-after-aborted.js | 21 | ||||
-rw-r--r-- | test/parallel/test-http-client-timeout-on-connect.js | 3 | ||||
-rw-r--r-- | test/parallel/test-http-writable-true-after-close.js | 2 |
6 files changed, 10 insertions, 60 deletions
diff --git a/doc/api/http.md b/doc/api/http.md index e9ed20f05f..cc0c7ae1ce 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -541,8 +541,7 @@ added: v0.3.8 --> Marks the request as aborting. Calling this will cause remaining data -in the response to be dropped and the socket to be destroyed. After -calling this method no further errors will be emitted. +in the response to be dropped and the socket to be destroyed. ### request.aborted <!-- YAML @@ -2143,6 +2142,8 @@ will be emitted in the following order: * `'socket'` * (`req.abort()` called here) * `'abort'` +* `'error'` with an error with message `'Error: socket hang up'` and code + `'ECONNRESET'` * `'close'` If `req.abort()` is called after the response is received, the following events diff --git a/lib/_http_client.js b/lib/_http_client.js index f2282e207d..a1750a1a00 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -374,9 +374,7 @@ function socketCloseListener() { // receive a response. The error needs to // fire on the request. req.socket._hadError = true; - if (!req.aborted) { - req.emit('error', connResetException('socket hang up')); - } + req.emit('error', connResetException('socket hang up')); } req.emit('close'); } @@ -402,9 +400,7 @@ function socketErrorListener(err) { // For Safety. Some additional errors might fire later on // and we need to make sure we don't double-fire the error event. req.socket._hadError = true; - if (!req.aborted) { - req.emit('error', err); - } + req.emit('error', err); } // Handle any pending data @@ -438,9 +434,7 @@ function socketOnEnd() { // If we don't have a response then we know that the socket // ended prematurely and we need to emit an error on the request. req.socket._hadError = true; - if (!req.aborted) { - req.emit('error', connResetException('socket hang up')); - } + req.emit('error', connResetException('socket hang up')); } if (parser) { parser.finish(); @@ -463,9 +457,7 @@ function socketOnData(d) { freeParser(parser, req, socket); socket.destroy(); req.socket._hadError = true; - if (!req.aborted) { - req.emit('error', ret); - } + req.emit('error', ret); } else if (parser.incoming && parser.incoming.upgrade) { // Upgrade (if status code 101) or CONNECT var bytesParsed = ret; diff --git a/test/parallel/test-http-client-aborted.js b/test/parallel/test-http-client-aborted.js deleted file mode 100644 index 58e8d589c7..0000000000 --- a/test/parallel/test-http-client-aborted.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict'; - -const common = require('../common'); -const http = require('http'); -const assert = require('assert'); - -const server = http.createServer(common.mustCall(function(req, res) { - req.on('aborted', common.mustCall(function() { - assert.strictEqual(this.aborted, true); - server.close(); - })); - assert.strictEqual(req.aborted, false); - res.write('hello'); -})); - -server.listen(0, common.mustCall(() => { - const req = http.get({ - port: server.address().port, - headers: { connection: 'keep-alive' } - }, common.mustCall((res) => { - req.abort(); - })); -})); diff --git a/test/parallel/test-http-client-no-error-after-aborted.js b/test/parallel/test-http-client-no-error-after-aborted.js deleted file mode 100644 index 21f72008a9..0000000000 --- a/test/parallel/test-http-client-no-error-after-aborted.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -const common = require('../common'); -const http = require('http'); - -const server = http.createServer(common.mustCall((req, res) => { - res.write('hello'); -})); - -server.listen(0, common.mustCall(() => { - const req = http.get({ - port: server.address().port - }, common.mustCall((res) => { - req.on('error', common.mustNotCall()); - req.abort(); - req.socket.destroy(new Error()); - req.on('close', common.mustCall(() => { - server.close(); - })); - })); -})); diff --git a/test/parallel/test-http-client-timeout-on-connect.js b/test/parallel/test-http-client-timeout-on-connect.js index d2c6975e25..3a0098229d 100644 --- a/test/parallel/test-http-client-timeout-on-connect.js +++ b/test/parallel/test-http-client-timeout-on-connect.js @@ -23,7 +23,8 @@ server.listen(0, common.localhostIPv4, common.mustCall(() => { })); })); req.on('timeout', common.mustCall(() => req.abort())); - req.on('abort', common.mustCall(() => { + req.on('error', common.mustCall((err) => { + assert.strictEqual(err.message, 'socket hang up'); server.close(); })); })); diff --git a/test/parallel/test-http-writable-true-after-close.js b/test/parallel/test-http-writable-true-after-close.js index 1174eec2ec..c0db7c3449 100644 --- a/test/parallel/test-http-writable-true-after-close.js +++ b/test/parallel/test-http-writable-true-after-close.js @@ -34,7 +34,7 @@ const server = createServer(common.mustCall((req, res) => { })); }).listen(0, () => { external = get(`http://127.0.0.1:${server.address().port}`); - external.on('abort', common.mustCall(() => { + external.on('error', common.mustCall(() => { server.close(); internal.close(); })); |