Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: client aborted should be boolean. #20230

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: aborted -> `aborted`?

-->

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a changes: block in the metadata for this property? (e.g. what we have for createServer() further below in the file)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


### request.connection
<!-- YAML
Expand Down
8 changes: 2 additions & 6 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-http-abort-stream-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down