Skip to content

Commit 68eaf08

Browse files
committed
http: add complete property
1 parent 02b82d8 commit 68eaf08

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

lib/_http_client.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ function ClientRequest(input, options, cb) {
298298
Object.setPrototypeOf(ClientRequest.prototype, OutgoingMessage.prototype);
299299
Object.setPrototypeOf(ClientRequest, OutgoingMessage);
300300

301+
Object.defineProperty(ClientRequest.prototype, 'complete', {
302+
get() {
303+
return Boolean(
304+
this.finished ||
305+
this.aborted ||
306+
this.closed
307+
);
308+
}
309+
});
310+
301311
ClientRequest.prototype._finish = function _finish() {
302312
DTRACE_HTTP_CLIENT_REQUEST(this, this.connection);
303313
OutgoingMessage.prototype._finish.call(this);

lib/_http_incoming.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ function IncomingMessage(socket) {
7777
Object.setPrototypeOf(IncomingMessage.prototype, Stream.Readable.prototype);
7878
Object.setPrototypeOf(IncomingMessage, Stream.Readable);
7979

80+
Object.defineProperty(IncomingMessage.prototype, 'complete', {
81+
get() {
82+
return Boolean(
83+
this.finished ||
84+
this.aborted ||
85+
this.closed
86+
);
87+
}
88+
});
89+
8090
IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
8191
if (callback)
8292
this.on('timeout', callback);

lib/_http_outgoing.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ function OutgoingMessage() {
110110
Object.setPrototypeOf(OutgoingMessage.prototype, Stream.prototype);
111111
Object.setPrototypeOf(OutgoingMessage, Stream);
112112

113+
Object.defineProperty(OutgoingMessage.prototype, 'complete', {
114+
get() {
115+
return Boolean(
116+
this.finished ||
117+
this.closed
118+
);
119+
}
120+
});
113121

114122
Object.defineProperty(OutgoingMessage.prototype, '_headers', {
115123
get: internalUtil.deprecate(function() {

lib/internal/http2/compat.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ class Http2ServerRequest extends Readable {
306306
}
307307

308308
get complete() {
309-
return this._readableState.ended ||
309+
return this[kAborted] ||
310+
this._readableState.ended ||
310311
this[kState].closed ||
311312
this[kStream].destroyed;
312313
}
@@ -454,6 +455,12 @@ class Http2ServerResponse extends Stream {
454455
return this[kState].closed;
455456
}
456457

458+
get complete() {
459+
return this._writableState.ended ||
460+
this[kState].closed ||
461+
this[kStream].destroyed;
462+
}
463+
457464
// User land modules such as finalhandler just check truthiness of this
458465
// but if someone is actually trying to use this for more than that
459466
// then we simply can't support such use cases

0 commit comments

Comments
 (0)