| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -541,7 +541,8 @@ added: v0.3.8 | |||
| 541 | 541 | --> | |
| 542 | 542 | ||
| 543 | 543 | Marks the request as aborting. Calling this will cause remaining data | |
| 544 | - in the response to be dropped and the socket to be destroyed. | ||
| 544 | + in the response to be dropped and the socket to be destroyed. After | ||
| 545 | + calling this method no further errors will be emitted. | ||
| 545 | 546 | ||
| 546 | 547 | ### request.aborted | |
| 547 | 548 | <!-- YAML | |
@@ -2142,8 +2143,6 @@ will be emitted in the following order: | |||
| 2142 | 2143 | * `'socket'` | |
| 2143 | 2144 | * (`req.abort()` called here) | |
| 2144 | 2145 | * `'abort'` | |
| 2145 | - * `'error'` with an error with message `'Error: socket hang up'` and code | ||
| 2146 | - `'ECONNRESET'` | ||
| 2147 | 2146 | * `'close'` | |
| 2148 | 2147 | ||
| 2149 | 2148 | If `req.abort()` is called after the response is received, the following events | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -374,7 +374,9 @@ function socketCloseListener() { | |||
| 374 | 374 | // receive a response. The error needs to | |
| 375 | 375 | // fire on the request. | |
| 376 | 376 | req.socket._hadError = true; | |
| 377 | - req.emit('error', connResetException('socket hang up')); | ||
| 377 | + if (!req.aborted) { | ||
| 378 | + req.emit('error', connResetException('socket hang up')); | ||
| 379 | + } | ||
| 378 | 380 | } | |
| 379 | 381 | req.emit('close'); | |
| 380 | 382 | } | |
@@ -400,7 +402,9 @@ function socketErrorListener(err) { | |||
| 400 | 402 | // For Safety. Some additional errors might fire later on | |
| 401 | 403 | // and we need to make sure we don't double-fire the error event. | |
| 402 | 404 | req.socket._hadError = true; | |
| 403 | - req.emit('error', err); | ||
| 405 | + if (!req.aborted) { | ||
| 406 | + req.emit('error', err); | ||
| 407 | + } | ||
| 404 | 408 | } | |
| 405 | 409 | ||
| 406 | 410 | // Handle any pending data | |
@@ -434,7 +438,9 @@ function socketOnEnd() { | |||
| 434 | 438 | // If we don't have a response then we know that the socket | |
| 435 | 439 | // ended prematurely and we need to emit an error on the request. | |
| 436 | 440 | req.socket._hadError = true; | |
| 437 | - req.emit('error', connResetException('socket hang up')); | ||
| 441 | + if (!req.aborted) { | ||
| 442 | + req.emit('error', connResetException('socket hang up')); | ||
| 443 | + } | ||
| 438 | 444 | } | |
| 439 | 445 | if (parser) { | |
| 440 | 446 | parser.finish(); | |
@@ -457,7 +463,9 @@ function socketOnData(d) { | |||
| 457 | 463 | freeParser(parser, req, socket); | |
| 458 | 464 | socket.destroy(); | |
| 459 | 465 | req.socket._hadError = true; | |
| 460 | - req.emit('error', ret); | ||
| 466 | + if (!req.aborted) { | ||
| 467 | + req.emit('error', ret); | ||
| 468 | + } | ||
| 461 | 469 | } else if (parser.incoming && parser.incoming.upgrade) { | |
| 462 | 470 | // Upgrade (if status code 101) or CONNECT | |
| 463 | 471 | var bytesParsed = ret; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,23 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const http = require('http'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + const server = http.createServer(common.mustCall(function(req, res) { | ||
| 8 | + req.on('aborted', common.mustCall(function() { | ||
| 9 | + assert.strictEqual(this.aborted, true); | ||
| 10 | + server.close(); | ||
| 11 | + })); | ||
| 12 | + assert.strictEqual(req.aborted, false); | ||
| 13 | + res.write('hello'); | ||
| 14 | + })); | ||
| 15 | + | ||
| 16 | + server.listen(0, common.mustCall(() => { | ||
| 17 | + const req = http.get({ | ||
| 18 | + port: server.address().port, | ||
| 19 | + headers: { connection: 'keep-alive' } | ||
| 20 | + }, common.mustCall((res) => { | ||
| 21 | + req.abort(); | ||
| 22 | + })); | ||
| 23 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,21 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const http = require('http'); | ||
| 5 | + | ||
| 6 | + const server = http.createServer(common.mustCall((req, res) => { | ||
| 7 | + res.write('hello'); | ||
| 8 | + })); | ||
| 9 | + | ||
| 10 | + server.listen(0, common.mustCall(() => { | ||
| 11 | + const req = http.get({ | ||
| 12 | + port: server.address().port | ||
| 13 | + }, common.mustCall((res) => { | ||
| 14 | + req.on('error', common.mustNotCall()); | ||
| 15 | + req.abort(); | ||
| 16 | + req.socket.destroy(new Error()); | ||
| 17 | + req.on('close', common.mustCall(() => { | ||
| 18 | + server.close(); | ||
| 19 | + })); | ||
| 20 | + })); | ||
| 21 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,8 +23,7 @@ server.listen(0, common.localhostIPv4, common.mustCall(() => { | |||
| 23 | 23 | })); | |
| 24 | 24 | })); | |
| 25 | 25 | req.on('timeout', common.mustCall(() => req.abort())); | |
| 26 | - req.on('error', common.mustCall((err) => { | ||
| 27 | - assert.strictEqual(err.message, 'socket hang up'); | ||
| 26 | + req.on('abort', common.mustCall(() => { | ||
| 28 | 27 | server.close(); | |
| 29 | 28 | })); | |
| 30 | 29 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,7 +34,7 @@ const server = createServer(common.mustCall((req, res) => { | |||
| 34 | 34 | })); | |
| 35 | 35 | }).listen(0, () => { | |
| 36 | 36 | external = get(`http://127.0.0.1:${server.address().port}`); | |
| 37 | - external.on('error', common.mustCall(() => { | ||
| 37 | + external.on('abort', common.mustCall(() => { | ||
| 38 | 38 | server.close(); | |
| 39 | 39 | internal.close(); | |
| 40 | 40 | })); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments