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: name anonymous functions #9055

Closed
wants to merge 5 commits 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
23 changes: 12 additions & 11 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
};

Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -645,21 +646,21 @@ 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++)
args[i] = arguments[i];
this._deferToConnect('setKeepAlive', args);
};

ClientRequest.prototype.clearTimeout = function(cb) {
ClientRequest.prototype.clearTimeout = function clearTimeout(cb) {
this.setTimeout(0, cb);
};
20 changes: 11 additions & 9 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ 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);
return this;
};


IncomingMessage.prototype.read = function(n) {
IncomingMessage.prototype.read = function read(n) {
if (!this._consuming)
this._readableState.readingMore = false;
this._consuming = true;
Expand All @@ -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.
Expand All @@ -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) {
Expand All @@ -119,7 +120,7 @@ IncomingMessage.prototype._addHeaderLines = function(headers, n) {
this._addHeaderLine(k, v, dest);
}
}
};
}


// Add the given (field, value) pair to the message
Expand All @@ -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:
Expand Down Expand Up @@ -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();
Expand Down
42 changes: 22 additions & 20 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function utcDate() {
}
return dateCache;
}
utcDate._onTimeout = function() {
utcDate._onTimeout = function _onTimeout() {
dateCache = undefined;
};

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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 = {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 + '"]');
Expand All @@ -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)');
}
Expand All @@ -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)');
}
Expand All @@ -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');
}
Expand All @@ -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');
};

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
};
Expand All @@ -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;

Expand Down Expand Up @@ -688,7 +690,7 @@ OutgoingMessage.prototype._flushOutput = function _flushOutput(socket) {
};


OutgoingMessage.prototype.flushHeaders = function() {
OutgoingMessage.prototype.flushHeaders = function flushHeaders() {
if (!this._header) {
this._implicitHeader();
}
Expand Down
Loading