Skip to content

Commit

Permalink
http: replace vars with lets and consts in lib/_http_agent.js
Browse files Browse the repository at this point in the history
PR-URL: #30301
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
palmires authored and MylesBorins committed Nov 17, 2019
1 parent bad0b66 commit a37ade8
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ function Agent(options) {
} else {
// If there are no pending requests, then put it in
// the freeSockets pool, but only if we're allowed to do so.
var req = socket._httpMessage;
const req = socket._httpMessage;
if (req &&
req.shouldKeepAlive &&
socket.writable &&
this.keepAlive) {
var freeSockets = this.freeSockets[name];
var freeLen = freeSockets ? freeSockets.length : 0;
var count = freeLen;
let freeSockets = this.freeSockets[name];
const freeLen = freeSockets ? freeSockets.length : 0;
let count = freeLen;
if (this.sockets[name])
count += this.sockets[name].length;

Expand Down Expand Up @@ -134,7 +134,7 @@ Agent.prototype.createConnection = net.createConnection;

// Get the key for a given set of request options
Agent.prototype.getName = function getName(options) {
var name = options.host || 'localhost';
let name = options.host || 'localhost';

name += ':';
if (options.port)
Expand Down Expand Up @@ -183,7 +183,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,

if (freeLen) {
// We have a free socket, so use that.
var socket = this.freeSockets[name].shift();
const socket = this.freeSockets[name].shift();
// Guard against an uninitialized or user supplied Socket.
const handle = socket._handle;
if (handle && typeof handle.asyncReset === 'function') {
Expand Down Expand Up @@ -226,7 +226,7 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {

debug('createConnection', name, options);
options.encoding = null;
var called = false;
let called = false;

const oncreate = (err, s) => {
if (called)
Expand Down Expand Up @@ -317,11 +317,11 @@ Agent.prototype.removeSocket = function removeSocket(s, options) {
if (!s.writable)
sets.push(this.freeSockets);

for (var sk = 0; sk < sets.length; sk++) {
var sockets = sets[sk];
for (let sk = 0; sk < sets.length; sk++) {
const sockets = sets[sk];

if (sockets[name]) {
var index = sockets[name].indexOf(s);
const index = sockets[name].indexOf(s);
if (index !== -1) {
sockets[name].splice(index, 1);
// Don't leak
Expand Down Expand Up @@ -355,12 +355,12 @@ Agent.prototype.reuseSocket = function reuseSocket(socket, req) {

Agent.prototype.destroy = function destroy() {
const sets = [this.freeSockets, this.sockets];
for (var s = 0; s < sets.length; s++) {
var set = sets[s];
var keys = Object.keys(set);
for (var v = 0; v < keys.length; v++) {
var setName = set[keys[v]];
for (var n = 0; n < setName.length; n++) {
for (let s = 0; s < sets.length; s++) {
const set = sets[s];
const keys = Object.keys(set);
for (let v = 0; v < keys.length; v++) {
const setName = set[keys[v]];
for (let n = 0; n < setName.length; n++) {
setName[n].destroy();
}
}
Expand Down

0 comments on commit a37ade8

Please sign in to comment.