Skip to content

Commit 4b00c4f

Browse files
ronagvsemozhetbyt
authored andcommitted
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>
1 parent 50b334b commit 4b00c4f

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

doc/api/http.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,16 @@ in the response to be dropped and the socket to be destroyed.
529529
### request.aborted
530530
<!-- YAML
531531
added: v0.11.14
532+
changes:
533+
- version: REPLACEME
534+
pr-url: https://github.com/nodejs/node/pull/20230
535+
description: The `aborted` property is no longer a timestamp number.
532536
-->
533537

534-
If a request has been aborted, this value is the time when the request was
535-
aborted, in milliseconds since 1 January 1970 00:00:00 UTC.
538+
* {boolean}
539+
540+
The `request.aborted` property will be `true` if the request has
541+
been aborted.
536542

537543
### request.connection
538544
<!-- YAML

lib/_http_client.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function ClientRequest(options, cb) {
165165

166166
this._ended = false;
167167
this.res = null;
168-
this.aborted = undefined;
168+
this.aborted = false;
169169
this.timeoutCb = null;
170170
this.upgradeOrConnect = false;
171171
this.parser = null;
@@ -291,11 +291,7 @@ ClientRequest.prototype.abort = function abort() {
291291
if (!this.aborted) {
292292
process.nextTick(emitAbortNT.bind(this));
293293
}
294-
295-
// Mark as aborting so we can avoid sending queued request data
296-
// This is used as a truthy flag elsewhere. The use of Date.now is for
297-
// debugging purposes only.
298-
this.aborted = Date.now();
294+
this.aborted = true;
299295

300296
// If we're aborting, we don't care about any more response data.
301297
if (this.res) {

test/parallel/test-http-abort-stream-end.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,20 @@ const server = http.createServer(common.mustCall((req, res) => {
3838
res.end();
3939
}));
4040

41-
let aborted = false;
4241
server.listen(0, () => {
43-
4442
const res = common.mustCall((res) => {
4543
res.on('data', (chunk) => {
4644
size += chunk.length;
47-
assert(!aborted, 'got data after abort');
45+
assert(!req.aborted, 'got data after abort');
4846
if (size > maxSize) {
49-
aborted = true;
5047
req.abort();
48+
assert.strictEqual(req.aborted, true);
5149
size = maxSize;
5250
}
5351
});
5452

5553
req.on('abort', common.mustCall(() => assert.strictEqual(size, maxSize)));
54+
assert.strictEqual(req.aborted, false);
5655
});
5756

5857
const req = http.get(`http://localhost:${server.address().port}`, res);

0 commit comments

Comments
 (0)