From dc9e3957375614040fdb0942e829322ae86bc829 Mon Sep 17 00:00:00 2001 From: Brian White Date: Fri, 26 Aug 2016 17:23:11 -0400 Subject: [PATCH] replace deprecated http.createClient() usage --- lib/utils.js | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 5c72990db..158f44dff 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -152,26 +152,35 @@ exports.httputil = function (cgi, envReady) { var server = http.createServer(cgi); server.listen(port, hostname); - var client = http.createClient(port, hostname); - client.fetch = function (method, path, headers, respReady) { - var request = this.request(method, path, headers); - request.end(); - request.on('response', function (response) { - response.setEncoding('utf8'); - response.on('data', function (chunk) { - if (response.body) { - response.body += chunk; - } else { - response.body = chunk; - } + var agent = new http.Agent({ host: hostname, port: port, maxSockets: 1 }); + var client = { + fetch: function (method, path, headers, respReady) { + var request = http.request({ + host: hostname, + port: port, + agent: agent, + method: method, + path: path, + headers: headers }); - response.on('end', function () { - if (response.headers['content-type'] === 'application/json') { - response.bodyAsObject = JSON.parse(response.body); - } - respReady(response); + request.end(); + request.on('response', function (response) { + response.setEncoding('utf8'); + response.on('data', function (chunk) { + if (response.body) { + response.body += chunk; + } else { + response.body = chunk; + } + }); + response.on('end', function () { + if (response.headers['content-type'] === 'application/json') { + response.bodyAsObject = JSON.parse(response.body); + } + respReady(response); + }); }); - }); + } }; process.nextTick(function () {