diff options
author | Robert Nagy <ronagy@icloud.com> | 2019-08-06 13:56:52 +0200 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-08-17 06:21:59 -0700 |
commit | 0daec61b9bdefbde1026f0dacb7ee38eb6a91771 (patch) | |
tree | 6597c5eb520cad876ded3c31c15c05d34df79a1b /lib | |
parent | 6f613d8abb05619e35c828b665a76215861bbf04 (diff) | |
download | android-node-v8-0daec61b9bdefbde1026f0dacb7ee38eb6a91771.tar.gz android-node-v8-0daec61b9bdefbde1026f0dacb7ee38eb6a91771.tar.bz2 android-node-v8-0daec61b9bdefbde1026f0dacb7ee38eb6a91771.zip |
http: replace superfluous connection property with getter/setter
PR-URL: https://github.com/nodejs/node/pull/29015
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/_http_client.js | 3 | ||||
-rw-r--r-- | lib/_http_incoming.js | 10 | ||||
-rw-r--r-- | lib/_http_outgoing.js | 30 | ||||
-rw-r--r-- | lib/_http_server.js | 5 |
4 files changed, 31 insertions, 17 deletions
diff --git a/lib/_http_client.js b/lib/_http_client.js index 08931132d2..956dd8da7a 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -299,7 +299,7 @@ Object.setPrototypeOf(ClientRequest.prototype, OutgoingMessage.prototype); Object.setPrototypeOf(ClientRequest, OutgoingMessage); ClientRequest.prototype._finish = function _finish() { - DTRACE_HTTP_CLIENT_REQUEST(this, this.connection); + DTRACE_HTTP_CLIENT_REQUEST(this, this.socket); OutgoingMessage.prototype._finish.call(this); }; @@ -643,7 +643,6 @@ function emitFreeNT(socket) { function tickOnSocket(req, socket) { const parser = parsers.alloc(); req.socket = socket; - req.connection = socket; parser.initialize(HTTPParser.RESPONSE, new HTTPClientAsyncResource('HTTPINCOMINGMESSAGE', req)); parser.socket = socket; diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js index 3ec23616b1..ad3699cc44 100644 --- a/lib/_http_incoming.js +++ b/lib/_http_incoming.js @@ -42,7 +42,6 @@ function IncomingMessage(socket) { this._readableState.readingMore = true; this.socket = socket; - this.connection = socket; this.httpVersionMajor = null; this.httpVersionMinor = null; @@ -76,6 +75,15 @@ function IncomingMessage(socket) { Object.setPrototypeOf(IncomingMessage.prototype, Stream.Readable.prototype); Object.setPrototypeOf(IncomingMessage, Stream.Readable); +Object.defineProperty(IncomingMessage.prototype, 'connection', { + get: function() { + return this.socket; + }, + set: function(val) { + this.socket = val; + } +}); + IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) { if (callback) this.on('timeout', callback); diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 2d2bbaa0e7..c56c6e4798 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -102,7 +102,6 @@ function OutgoingMessage() { this[kIsCorked] = false; this.socket = null; - this.connection = null; this._header = null; this[kOutHeaders] = null; @@ -157,6 +156,15 @@ Object.defineProperty(OutgoingMessage.prototype, '_headers', { }, 'OutgoingMessage.prototype._headers is deprecated', 'DEP0066') }); +Object.defineProperty(OutgoingMessage.prototype, 'connection', { + get: function() { + return this.socket; + }, + set: function(val) { + this.socket = val; + } +}); + Object.defineProperty(OutgoingMessage.prototype, '_headerNames', { get: internalUtil.deprecate(function() { const headers = this[kOutHeaders]; @@ -273,7 +281,7 @@ OutgoingMessage.prototype._send = function _send(data, encoding, callback) { OutgoingMessage.prototype._writeRaw = _writeRaw; function _writeRaw(data, encoding, callback) { - const conn = this.connection; + const conn = this.socket; if (conn && conn.destroyed) { // The socket was destroyed. If we're still trying to write to it, // then we haven't gotten the 'close' event yet. @@ -615,10 +623,10 @@ function write_(msg, chunk, encoding, callback, fromEnd) { ['string', 'Buffer'], chunk); } - if (!fromEnd && msg.connection && !msg[kIsCorked]) { - msg.connection.cork(); + if (!fromEnd && msg.socket && !msg[kIsCorked]) { + msg.socket.cork(); msg[kIsCorked] = true; - process.nextTick(connectionCorkNT, msg, msg.connection); + process.nextTick(connectionCorkNT, msg, msg.socket); } var len, ret; @@ -706,8 +714,8 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) { else this._contentLength = chunk.length; } - if (this.connection) { - this.connection.cork(); + if (this.socket) { + this.socket.cork(); uncork = true; } write_(this, chunk, encoding, null, true); @@ -729,7 +737,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) { } if (uncork) - this.connection.uncork(); + this.socket.uncork(); this.finished = true; @@ -737,8 +745,8 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) { // everything to the socket. debug('outgoing message end.'); if (this.outputData.length === 0 && - this.connection && - this.connection._httpMessage === this) { + this.socket && + this.socket._httpMessage === this) { this._finish(); } @@ -747,7 +755,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) { OutgoingMessage.prototype._finish = function _finish() { - assert(this.connection); + assert(this.socket); this.emit('prefinish'); }; diff --git a/lib/_http_server.js b/lib/_http_server.js index 9a862420d4..b083983c94 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -167,7 +167,7 @@ Object.setPrototypeOf(ServerResponse.prototype, OutgoingMessage.prototype); Object.setPrototypeOf(ServerResponse, OutgoingMessage); ServerResponse.prototype._finish = function _finish() { - DTRACE_HTTP_SERVER_RESPONSE(this.connection); + DTRACE_HTTP_SERVER_RESPONSE(this.socket); if (this[kServerResponseStatistics] !== undefined) { emitStatistics(this[kServerResponseStatistics]); } @@ -205,7 +205,6 @@ ServerResponse.prototype.assignSocket = function assignSocket(socket) { socket._httpMessage = this; socket.on('close', onServerResponseClose); this.socket = socket; - this.connection = socket; this.emit('socket', socket); this._flush(); }; @@ -214,7 +213,7 @@ ServerResponse.prototype.detachSocket = function detachSocket(socket) { assert(socket._httpMessage === this); socket.removeListener('close', onServerResponseClose); socket._httpMessage = null; - this.socket = this.connection = null; + this.socket = null; }; ServerResponse.prototype.writeContinue = function writeContinue(cb) { |