Permalink
Browse files

http: make client `.aborted` boolean

PR-URL: #20230
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
ronag authored and vsemozhetbyt committed Apr 26, 2018
1 parent 50b334b commit 4b00c4fafaa2ae8c41c1f78823c0feb810ae4723
Showing with 13 additions and 12 deletions.
  1. +8 −2 doc/api/http.md
  2. +2 −6 lib/_http_client.js
  3. +3 −4 test/parallel/test-http-abort-stream-end.js
View
@@ -529,10 +529,16 @@ in the response to be dropped and the socket to be destroyed.
### request.aborted
<!-- YAML
added: v0.11.14
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/20230
description: The `aborted` property is no longer a timestamp number.
-->
If a request has been aborted, this value is the time when the request was
aborted, in milliseconds since 1 January 1970 00:00:00 UTC.
* {boolean}
The `request.aborted` property will be `true` if the request has
been aborted.
### request.connection
<!-- YAML
View
@@ -165,7 +165,7 @@ function ClientRequest(options, cb) {
this._ended = false;
this.res = null;
this.aborted = undefined;
this.aborted = false;
this.timeoutCb = null;
this.upgradeOrConnect = false;
this.parser = null;
@@ -291,11 +291,7 @@ ClientRequest.prototype.abort = function abort() {
if (!this.aborted) {
process.nextTick(emitAbortNT.bind(this));
}
// Mark as aborting so we can avoid sending queued request data
// This is used as a truthy flag elsewhere. The use of Date.now is for
// debugging purposes only.
this.aborted = Date.now();
this.aborted = true;
// If we're aborting, we don't care about any more response data.
if (this.res) {
@@ -38,21 +38,20 @@ const server = http.createServer(common.mustCall((req, res) => {
res.end();
}));
let aborted = false;
server.listen(0, () => {
const res = common.mustCall((res) => {
res.on('data', (chunk) => {
size += chunk.length;
assert(!aborted, 'got data after abort');
assert(!req.aborted, 'got data after abort');
if (size > maxSize) {
aborted = true;
req.abort();
assert.strictEqual(req.aborted, true);
size = maxSize;
}
});
req.on('abort', common.mustCall(() => assert.strictEqual(size, maxSize)));
assert.strictEqual(req.aborted, false);
});
const req = http.get(`http://localhost:${server.address().port}`, res);

0 comments on commit 4b00c4f

Please sign in to comment.