Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9b8e2a6

Browse filesBrowse files
benglgibfahn
authored andcommitted
http: use arrow fns for lexical this in Agent
PR-URL: #16475 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 6583016 commit 9b8e2a6
Copy full SHA for 9b8e2a6

File tree

Expand file treeCollapse file tree

1 file changed

+39
-41
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+39
-41
lines changed
Open diff view settings
Collapse file

‎lib/_http_agent.js‎

Copy file name to clipboardExpand all lines: lib/_http_agent.js
+39-41Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,31 @@ function Agent(options) {
4646

4747
EventEmitter.call(this);
4848

49-
var self = this;
49+
this.defaultPort = 80;
50+
this.protocol = 'http:';
5051

51-
self.defaultPort = 80;
52-
self.protocol = 'http:';
53-
54-
self.options = util._extend({}, options);
52+
this.options = util._extend({}, options);
5553

5654
// don't confuse net and make it think that we're connecting to a pipe
57-
self.options.path = null;
58-
self.requests = {};
59-
self.sockets = {};
60-
self.freeSockets = {};
61-
self.keepAliveMsecs = self.options.keepAliveMsecs || 1000;
62-
self.keepAlive = self.options.keepAlive || false;
63-
self.maxSockets = self.options.maxSockets || Agent.defaultMaxSockets;
64-
self.maxFreeSockets = self.options.maxFreeSockets || 256;
65-
66-
self.on('free', function(socket, options) {
67-
var name = self.getName(options);
55+
this.options.path = null;
56+
this.requests = {};
57+
this.sockets = {};
58+
this.freeSockets = {};
59+
this.keepAliveMsecs = this.options.keepAliveMsecs || 1000;
60+
this.keepAlive = this.options.keepAlive || false;
61+
this.maxSockets = this.options.maxSockets || Agent.defaultMaxSockets;
62+
this.maxFreeSockets = this.options.maxFreeSockets || 256;
63+
64+
this.on('free', (socket, options) => {
65+
var name = this.getName(options);
6866
debug('agent.on(free)', name);
6967

7068
if (socket.writable &&
71-
self.requests[name] && self.requests[name].length) {
72-
self.requests[name].shift().onSocket(socket);
73-
if (self.requests[name].length === 0) {
69+
this.requests[name] && this.requests[name].length) {
70+
this.requests[name].shift().onSocket(socket);
71+
if (this.requests[name].length === 0) {
7472
// don't leak
75-
delete self.requests[name];
73+
delete this.requests[name];
7674
}
7775
} else {
7876
// If there are no pending requests, then put it in
@@ -81,21 +79,21 @@ function Agent(options) {
8179
if (req &&
8280
req.shouldKeepAlive &&
8381
socket.writable &&
84-
self.keepAlive) {
85-
var freeSockets = self.freeSockets[name];
82+
this.keepAlive) {
83+
var freeSockets = this.freeSockets[name];
8684
var freeLen = freeSockets ? freeSockets.length : 0;
8785
var count = freeLen;
88-
if (self.sockets[name])
89-
count += self.sockets[name].length;
86+
if (this.sockets[name])
87+
count += this.sockets[name].length;
9088

91-
if (count > self.maxSockets || freeLen >= self.maxFreeSockets) {
89+
if (count > this.maxSockets || freeLen >= this.maxFreeSockets) {
9290
socket.destroy();
93-
} else if (self.keepSocketAlive(socket)) {
91+
} else if (this.keepSocketAlive(socket)) {
9492
freeSockets = freeSockets || [];
95-
self.freeSockets[name] = freeSockets;
93+
this.freeSockets[name] = freeSockets;
9694
socket[async_id_symbol] = -1;
9795
socket._httpMessage = null;
98-
self.removeSocket(socket, options);
96+
this.removeSocket(socket, options);
9997
freeSockets.push(socket);
10098
} else {
10199
// Implementation doesn't want to keep socket alive
@@ -201,9 +199,8 @@ Agent.prototype.addRequest = function addRequest(req, options, port/*legacy*/,
201199
};
202200

203201
Agent.prototype.createSocket = function createSocket(req, options, cb) {
204-
var self = this;
205202
options = util._extend({}, options);
206-
util._extend(options, self.options);
203+
util._extend(options, this.options);
207204
if (options.socketPath)
208205
options.path = options.socketPath;
209206

@@ -215,30 +212,31 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
215212
}
216213
}
217214

218-
var name = self.getName(options);
215+
var name = this.getName(options);
219216
options._agentKey = name;
220217

221218
debug('createConnection', name, options);
222219
options.encoding = null;
223220
var called = false;
224-
const newSocket = self.createConnection(options, oncreate);
225-
if (newSocket)
226-
oncreate(null, newSocket);
227221

228-
function oncreate(err, s) {
222+
const oncreate = (err, s) => {
229223
if (called)
230224
return;
231225
called = true;
232226
if (err)
233227
return cb(err);
234-
if (!self.sockets[name]) {
235-
self.sockets[name] = [];
228+
if (!this.sockets[name]) {
229+
this.sockets[name] = [];
236230
}
237-
self.sockets[name].push(s);
238-
debug('sockets', name, self.sockets[name].length);
239-
installListeners(self, s, options);
231+
this.sockets[name].push(s);
232+
debug('sockets', name, this.sockets[name].length);
233+
installListeners(this, s, options);
240234
cb(null, s);
241-
}
235+
};
236+
237+
const newSocket = this.createConnection(options, oncreate);
238+
if (newSocket)
239+
oncreate(null, newSocket);
242240
};
243241

244242
function installListeners(agent, s, options) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.