From 453112aa18d025204988627c0241fb90a9b5d188 Mon Sep 17 00:00:00 2001 From: maasencioh Date: Wed, 12 Oct 2016 13:06:30 +0200 Subject: [PATCH 1/5] http: name anonymous functions in _http_client Ref: https://github.com/nodejs/node/issues/8913 --- lib/_http_client.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index 423445d6a6f091..abe4273f877b5e 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -207,19 +207,19 @@ exports.ClientRequest = ClientRequest; ClientRequest.prototype.aborted = undefined; -ClientRequest.prototype._finish = function() { +ClientRequest.prototype._finish = function _finish() { DTRACE_HTTP_CLIENT_REQUEST(this, this.connection); LTTNG_HTTP_CLIENT_REQUEST(this, this.connection); COUNTER_HTTP_CLIENT_REQUEST(); OutgoingMessage.prototype._finish.call(this); }; -ClientRequest.prototype._implicitHeader = function() { +ClientRequest.prototype._implicitHeader = function _implicitHeader() { this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n', this._renderHeaders()); }; -ClientRequest.prototype.abort = function() { +ClientRequest.prototype.abort = function abort() { if (this.aborted === undefined) { process.nextTick(emitAbortNT, this); } @@ -568,7 +568,7 @@ function tickOnSocket(req, socket) { req.emit('socket', socket); } -ClientRequest.prototype.onSocket = function(socket) { +ClientRequest.prototype.onSocket = function onSocket(socket) { process.nextTick(onSocketNT, this, socket); }; @@ -581,7 +581,8 @@ function onSocketNT(req, socket) { } } -ClientRequest.prototype._deferToConnect = function(method, arguments_, cb) { +ClientRequest.prototype._deferToConnect = _deferToConnect; +function _deferToConnect(method, arguments_, cb) { // This function is for calls that need to happen once the socket is // connected and writable. It's an important promisy thing for all the socket // calls that happen either now (when a socket is assigned) or @@ -597,7 +598,7 @@ ClientRequest.prototype._deferToConnect = function(method, arguments_, cb) { cb(); } - var onSocket = function() { + var onSocket = function onSocket() { if (self.socket.writable) { callSocketMethod(); } else { @@ -610,9 +611,9 @@ ClientRequest.prototype._deferToConnect = function(method, arguments_, cb) { } else { onSocket(); } -}; +} -ClientRequest.prototype.setTimeout = function(msecs, callback) { +ClientRequest.prototype.setTimeout = function setTimeout(msecs, callback) { if (callback) this.once('timeout', callback); var self = this; @@ -645,14 +646,14 @@ ClientRequest.prototype.setTimeout = function(msecs, callback) { return this; }; -ClientRequest.prototype.setNoDelay = function() { +ClientRequest.prototype.setNoDelay = function setNoDelay() { const argsLen = arguments.length; const args = new Array(argsLen); for (var i = 0; i < argsLen; i++) args[i] = arguments[i]; this._deferToConnect('setNoDelay', args); }; -ClientRequest.prototype.setSocketKeepAlive = function() { +ClientRequest.prototype.setSocketKeepAlive = function setSocketKeepAlive() { const argsLen = arguments.length; const args = new Array(argsLen); for (var i = 0; i < argsLen; i++) @@ -660,6 +661,6 @@ ClientRequest.prototype.setSocketKeepAlive = function() { this._deferToConnect('setKeepAlive', args); }; -ClientRequest.prototype.clearTimeout = function(cb) { +ClientRequest.prototype.clearTimeout = function clearTimeout(cb) { this.setTimeout(0, cb); }; From 2a3e9e47c56f48f7ccb58572d2f97fe73a94402e Mon Sep 17 00:00:00 2001 From: maasencioh Date: Wed, 12 Oct 2016 15:47:06 +0200 Subject: [PATCH 2/5] http: name anonymous functions in _http_incoming Ref: https://github.com/nodejs/node/issues/8913 --- lib/_http_incoming.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js index 4d1c3ea810e0cc..5c04ab9dfe3331 100644 --- a/lib/_http_incoming.js +++ b/lib/_http_incoming.js @@ -65,7 +65,7 @@ util.inherits(IncomingMessage, Stream.Readable); exports.IncomingMessage = IncomingMessage; -IncomingMessage.prototype.setTimeout = function(msecs, callback) { +IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) { if (callback) this.on('timeout', callback); this.socket.setTimeout(msecs); @@ -73,7 +73,7 @@ IncomingMessage.prototype.setTimeout = function(msecs, callback) { }; -IncomingMessage.prototype.read = function(n) { +IncomingMessage.prototype.read = function read(n) { if (!this._consuming) this._readableState.readingMore = false; this._consuming = true; @@ -82,7 +82,7 @@ IncomingMessage.prototype.read = function(n) { }; -IncomingMessage.prototype._read = function(n) { +IncomingMessage.prototype._read = function _read(n) { // We actually do almost nothing here, because the parserOnBody // function fills up our internal buffer directly. However, we // do need to unpause the underlying socket so that it flows. @@ -94,13 +94,14 @@ IncomingMessage.prototype._read = function(n) { // It's possible that the socket will be destroyed, and removed from // any messages, before ever calling this. In that case, just skip // it, since something else is destroying this connection anyway. -IncomingMessage.prototype.destroy = function(error) { +IncomingMessage.prototype.destroy = function destroy(error) { if (this.socket) this.socket.destroy(error); }; -IncomingMessage.prototype._addHeaderLines = function(headers, n) { +IncomingMessage.prototype._addHeaderLines = _addHeaderLines; +function _addHeaderLines(headers, n) { if (headers && headers.length) { var raw, dest; if (this.complete) { @@ -119,7 +120,7 @@ IncomingMessage.prototype._addHeaderLines = function(headers, n) { this._addHeaderLine(k, v, dest); } } -}; +} // Add the given (field, value) pair to the message @@ -129,7 +130,8 @@ IncomingMessage.prototype._addHeaderLines = function(headers, n) { // multiple values this way. If not, we declare the first instance the winner // and drop the second. Extended header fields (those beginning with 'x-') are // always joined. -IncomingMessage.prototype._addHeaderLine = function(field, value, dest) { +IncomingMessage.prototype._addHeaderLine = _addHeaderLine; +function _addHeaderLine(field, value, dest) { field = field.toLowerCase(); switch (field) { // Array headers: @@ -176,12 +178,12 @@ IncomingMessage.prototype._addHeaderLine = function(field, value, dest) { dest[field] = value; } } -}; +} // Call this instead of resume() if we want to just // dump all the data to /dev/null -IncomingMessage.prototype._dump = function() { +IncomingMessage.prototype._dump = function _dump() { if (!this._dumped) { this._dumped = true; this.resume(); From 8f855b45ce216d8e7924cfa01972825457f286c4 Mon Sep 17 00:00:00 2001 From: maasencioh Date: Wed, 12 Oct 2016 15:48:40 +0200 Subject: [PATCH 3/5] http: name anonymous functions in _http_outgoing Ref: https://github.com/nodejs/node/issues/8913 --- lib/_http_outgoing.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 7681222cf37fc6..09459480565413 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -40,7 +40,7 @@ function utcDate() { } return dateCache; } -utcDate._onTimeout = function() { +utcDate._onTimeout = function _onTimeout() { dateCache = undefined; }; @@ -91,7 +91,7 @@ util.inherits(OutgoingMessage, Stream); exports.OutgoingMessage = OutgoingMessage; -OutgoingMessage.prototype.setTimeout = function(msecs, callback) { +OutgoingMessage.prototype.setTimeout = function setTimeout(msecs, callback) { if (callback) { this.on('timeout', callback); @@ -111,7 +111,7 @@ OutgoingMessage.prototype.setTimeout = function(msecs, callback) { // It's possible that the socket will be destroyed, and removed from // any messages, before ever calling this. In that case, just skip // it, since something else is destroying this connection anyway. -OutgoingMessage.prototype.destroy = function(error) { +OutgoingMessage.prototype.destroy = function destroy(error) { if (this.socket) this.socket.destroy(error); else @@ -122,7 +122,7 @@ OutgoingMessage.prototype.destroy = function(error) { // This abstract either writing directly to the socket or buffering it. -OutgoingMessage.prototype._send = function(data, encoding, callback) { +OutgoingMessage.prototype._send = function _send(data, encoding, callback) { // This is a shameful hack to get the headers and first body chunk onto // the same packet. Future versions of Node are going to take care of // this at a lower level and in a more general way. @@ -145,7 +145,8 @@ OutgoingMessage.prototype._send = function(data, encoding, callback) { }; -OutgoingMessage.prototype._writeRaw = function(data, encoding, callback) { +OutgoingMessage.prototype._writeRaw = _writeRaw; +function _writeRaw(data, encoding, callback) { if (typeof encoding === 'function') { callback = encoding; encoding = null; @@ -176,10 +177,10 @@ OutgoingMessage.prototype._writeRaw = function(data, encoding, callback) { // buffer, as long as we're not destroyed. return this._buffer(data, encoding, callback); } -}; +} -OutgoingMessage.prototype._buffer = function(data, encoding, callback) { +OutgoingMessage.prototype._buffer = function _buffer(data, encoding, callback) { this.output.push(data); this.outputEncodings.push(encoding); this.outputCallbacks.push(callback); @@ -190,7 +191,8 @@ OutgoingMessage.prototype._buffer = function(data, encoding, callback) { }; -OutgoingMessage.prototype._storeHeader = function(firstLine, headers) { +OutgoingMessage.prototype._storeHeader = _storeHeader; +function _storeHeader(firstLine, headers) { // firstLine in the case of request is: 'GET /index.html HTTP/1.1\r\n' // in the case of response it is: 'HTTP/1.1 200 OK\r\n' var state = { @@ -307,7 +309,7 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) { // wait until the first body chunk, or close(), is sent to flush, // UNLESS we're sending Expect: 100-continue. if (state.sentExpect) this._send(''); -}; +} function storeHeader(self, state, field, value) { if (!common._checkIsHttpToken(field)) { @@ -346,7 +348,7 @@ function storeHeader(self, state, field, value) { } -OutgoingMessage.prototype.setHeader = function(name, value) { +OutgoingMessage.prototype.setHeader = function setHeader(name, value) { if (!common._checkIsHttpToken(name)) throw new TypeError( 'Header name must be a valid HTTP Token ["' + name + '"]'); @@ -369,7 +371,7 @@ OutgoingMessage.prototype.setHeader = function(name, value) { }; -OutgoingMessage.prototype.getHeader = function(name) { +OutgoingMessage.prototype.getHeader = function getHeader(name) { if (arguments.length < 1) { throw new Error('"name" argument is required for getHeader(name)'); } @@ -381,7 +383,7 @@ OutgoingMessage.prototype.getHeader = function(name) { }; -OutgoingMessage.prototype.removeHeader = function(name) { +OutgoingMessage.prototype.removeHeader = function removeHeader(name) { if (arguments.length < 1) { throw new Error('"name" argument is required for removeHeader(name)'); } @@ -404,7 +406,7 @@ OutgoingMessage.prototype.removeHeader = function(name) { }; -OutgoingMessage.prototype._renderHeaders = function() { +OutgoingMessage.prototype._renderHeaders = function _renderHeaders() { if (this._header) { throw new Error('Can\'t render headers after they are sent to the client'); } @@ -423,7 +425,7 @@ OutgoingMessage.prototype._renderHeaders = function() { return headers; }; -OutgoingMessage.prototype._implicitHeader = function() { +OutgoingMessage.prototype._implicitHeader = function _implicitHeader() { throw new Error('_implicitHeader() method is not implemented'); }; @@ -434,7 +436,7 @@ Object.defineProperty(OutgoingMessage.prototype, 'headersSent', { }); -OutgoingMessage.prototype.write = function(chunk, encoding, callback) { +OutgoingMessage.prototype.write = function write(chunk, encoding, callback) { if (this.finished) { var err = new Error('write after end'); process.nextTick(writeAfterEndNT, this, err, callback); @@ -513,7 +515,7 @@ function escapeHeaderValue(value) { } -OutgoingMessage.prototype.addTrailers = function(headers) { +OutgoingMessage.prototype.addTrailers = function addTrailers(headers) { this._trailer = ''; var keys = Object.keys(headers); var isArray = Array.isArray(headers); @@ -542,7 +544,7 @@ OutgoingMessage.prototype.addTrailers = function(headers) { const crlf_buf = Buffer.from('\r\n'); -OutgoingMessage.prototype.end = function(data, encoding, callback) { +OutgoingMessage.prototype.end = function end(data, encoding, callback) { if (typeof data === 'function') { callback = data; data = null; @@ -618,7 +620,7 @@ OutgoingMessage.prototype.end = function(data, encoding, callback) { }; -OutgoingMessage.prototype._finish = function() { +OutgoingMessage.prototype._finish = function _finish() { assert(this.connection); this.emit('prefinish'); }; @@ -643,7 +645,7 @@ OutgoingMessage.prototype._finish = function() { // // This function, outgoingFlush(), is called by both the Server and Client // to attempt to flush any pending messages out to the socket. -OutgoingMessage.prototype._flush = function() { +OutgoingMessage.prototype._flush = function _flush() { var socket = this.socket; var ret; @@ -688,7 +690,7 @@ OutgoingMessage.prototype._flushOutput = function _flushOutput(socket) { }; -OutgoingMessage.prototype.flushHeaders = function() { +OutgoingMessage.prototype.flushHeaders = function flushHeaders() { if (!this._header) { this._implicitHeader(); } From 0f3a6916af6ce613415179a7ca12eb9dc8c48033 Mon Sep 17 00:00:00 2001 From: maasencioh Date: Wed, 12 Oct 2016 15:50:15 +0200 Subject: [PATCH 4/5] http: name anonymous functions in _http_server Ref: https://github.com/nodejs/node/issues/8913 --- lib/_http_server.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/_http_server.js b/lib/_http_server.js index 731c95bb44a5fd..99671832ebb2cb 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -96,7 +96,7 @@ function ServerResponse(req) { } util.inherits(ServerResponse, OutgoingMessage); -ServerResponse.prototype._finish = function() { +ServerResponse.prototype._finish = function _finish() { DTRACE_HTTP_SERVER_RESPONSE(this.connection); LTTNG_HTTP_SERVER_RESPONSE(this.connection); COUNTER_HTTP_SERVER_RESPONSE(); @@ -131,7 +131,7 @@ function onServerResponseClose() { if (this._httpMessage) this._httpMessage.emit('close'); } -ServerResponse.prototype.assignSocket = function(socket) { +ServerResponse.prototype.assignSocket = function assignSocket(socket) { assert(!socket._httpMessage); socket._httpMessage = this; socket.on('close', onServerResponseClose); @@ -141,23 +141,24 @@ ServerResponse.prototype.assignSocket = function(socket) { this._flush(); }; -ServerResponse.prototype.detachSocket = function(socket) { +ServerResponse.prototype.detachSocket = function detachSocket(socket) { assert(socket._httpMessage === this); socket.removeListener('close', onServerResponseClose); socket._httpMessage = null; this.socket = this.connection = null; }; -ServerResponse.prototype.writeContinue = function(cb) { +ServerResponse.prototype.writeContinue = function writeContinue(cb) { this._writeRaw('HTTP/1.1 100 Continue' + CRLF + CRLF, 'ascii', cb); this._sent100 = true; }; -ServerResponse.prototype._implicitHeader = function() { +ServerResponse.prototype._implicitHeader = function _implicitHeader() { this.writeHead(this.statusCode); }; -ServerResponse.prototype.writeHead = function(statusCode, reason, obj) { +ServerResponse.prototype.writeHead = writeHead; +function writeHead(statusCode, reason, obj) { var headers; if (typeof reason === 'string') { @@ -219,9 +220,9 @@ ServerResponse.prototype.writeHead = function(statusCode, reason, obj) { } this._storeHeader(statusLine, headers); -}; +} -ServerResponse.prototype.writeHeader = function() { +ServerResponse.prototype.writeHeader = function writeHeader() { this.writeHead.apply(this, arguments); }; @@ -250,7 +251,7 @@ function Server(requestListener) { util.inherits(Server, net.Server); -Server.prototype.setTimeout = function(msecs, callback) { +Server.prototype.setTimeout = function setTimeout(msecs, callback) { this.timeout = msecs; if (callback) this.on('timeout', callback); From 63fcd957486519e6231d7e2b3cf929714aeacf3d Mon Sep 17 00:00:00 2001 From: maasencioh Date: Thu, 13 Oct 2016 13:01:28 +0200 Subject: [PATCH 5/5] http: name anonymous functions in http Ref: nodejs#8913 --- lib/http.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/http.js b/lib/http.js index 7e5b4bf9aa6137..6931a0e26c138a 100644 --- a/lib/http.js +++ b/lib/http.js @@ -15,18 +15,18 @@ exports.STATUS_CODES = server.STATUS_CODES; exports._connectionListener = server._connectionListener; const Server = exports.Server = server.Server; -exports.createServer = function(requestListener) { +exports.createServer = function createServer(requestListener) { return new Server(requestListener); }; const client = require('_http_client'); const ClientRequest = exports.ClientRequest = client.ClientRequest; -exports.request = function(options, cb) { +exports.request = function request(options, cb) { return new ClientRequest(options, cb); }; -exports.get = function(options, cb) { +exports.get = function get(options, cb) { var req = exports.request(options, cb); req.end(); return req;