diff options
author | Kat Marchán <kzm@zkat.tech> | 2019-02-18 21:34:46 +0300 |
---|---|---|
committer | Kat Marchán <kzm@zkat.tech> | 2019-02-19 01:32:16 +0300 |
commit | ee6b6746b04f145dfe489af2d26667ac32ba0cef (patch) | |
tree | d036525f18a06a431f16c162af8163e1bbb2ec59 /node_modules/agent-base | |
parent | cec1e82ff3ad09a259a524a99cf91a0fed14aa17 (diff) |
agent-base@4.2.1
Credit: @TooTallNate
Fixes: https://github.com/zkat/make-fetch-happen/issues/29
Diffstat (limited to 'node_modules/agent-base')
-rw-r--r-- | node_modules/agent-base/index.js | 12 | ||||
-rw-r--r-- | node_modules/agent-base/package.json | 28 | ||||
-rw-r--r-- | node_modules/agent-base/test/test.js | 24 |
3 files changed, 49 insertions, 15 deletions
diff --git a/node_modules/agent-base/index.js b/node_modules/agent-base/index.js index b1f42e631..0ee6b2969 100644 --- a/node_modules/agent-base/index.js +++ b/node_modules/agent-base/index.js @@ -94,6 +94,7 @@ Agent.prototype.addRequest = function addRequest(req, _opts) { let timeout; let timedOut = false; const timeoutMs = this.timeout; + const freeSocket = this.freeSocket; function onerror(err) { if (req._hadError) return; @@ -133,10 +134,14 @@ Agent.prototype.addRequest = function addRequest(req, _opts) { // responsibility for this `req` to the Agent from here on socket.addRequest(req, opts); } else if (socket) { + function onfree() { + freeSocket(socket, opts); + } + socket.on('free', onfree); req.onSocket(socket); } else { const err = new Error( - `no Duplex stream was returned to agent-base for \`${req.method} ${req.path}\`` + 'no Duplex stream was returned to agent-base for `' + req.method + ' ' + req.path + '`' ); onerror(err); } @@ -158,3 +163,8 @@ Agent.prototype.addRequest = function addRequest(req, _opts) { Promise.reject(err).catch(callbackError); } }; + +Agent.prototype.freeSocket = function freeSocket(socket, opts) { + // TODO reuse sockets + socket.destroy(); +}; diff --git a/node_modules/agent-base/package.json b/node_modules/agent-base/package.json index 59c5e0be2..08c5330de 100644 --- a/node_modules/agent-base/package.json +++ b/node_modules/agent-base/package.json @@ -1,31 +1,31 @@ { - "_from": "agent-base@4", - "_id": "agent-base@4.2.0", + "_from": "agent-base@latest", + "_id": "agent-base@4.2.1", "_inBundle": false, - "_integrity": "sha512-c+R/U5X+2zz2+UCrCFv6odQzJdoqI+YecuhnAJLa1zYaMc13zPfwMwZrr91Pd1DYNo/yPRbiM4WVf9whgwFsIg==", + "_integrity": "sha512-JVwXMr9nHYTUXsBFKUqhJwvlcYU/blreOEUkhNR2eXZIvwd+c+o5V4MgDPKWnMS/56awN3TRzIP+KoPn+roQtg==", "_location": "/agent-base", "_phantomChildren": {}, "_requested": { - "type": "range", + "type": "tag", "registry": true, - "raw": "agent-base@4", + "raw": "agent-base@latest", "name": "agent-base", "escapedName": "agent-base", - "rawSpec": "4", + "rawSpec": "latest", "saveSpec": null, - "fetchSpec": "4" + "fetchSpec": "latest" }, "_requiredBy": [ + "#USER", + "/", "/http-proxy-agent", "/https-proxy-agent", - "/npm-profile/socks-proxy-agent", - "/npm-registry-fetch/socks-proxy-agent", "/socks-proxy-agent" ], - "_resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.0.tgz", - "_shasum": "9838b5c3392b962bad031e6a4c5e1024abec45ce", - "_spec": "agent-base@4", - "_where": "/Users/rebecca/code/npm/node_modules/http-proxy-agent", + "_resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.1.tgz", + "_shasum": "d89e5999f797875674c07d87f260fc41e83e8ca9", + "_spec": "agent-base@latest", + "_where": "/Users/zkat/Documents/code/work/npm", "author": { "name": "Nathan Rajlich", "email": "nathan@tootallnate.net", @@ -65,5 +65,5 @@ "scripts": { "test": "mocha --reporter spec" }, - "version": "4.2.0" + "version": "4.2.1" } diff --git a/node_modules/agent-base/test/test.js b/node_modules/agent-base/test/test.js index da2e91983..6a8ca68e0 100644 --- a/node_modules/agent-base/test/test.js +++ b/node_modules/agent-base/test/test.js @@ -398,6 +398,30 @@ describe('"http" module', function() { }); }); + it('should free sockets after use', function(done) { + var agent = new Agent(function(req, opts, fn) { + var socket = net.connect(opts); + fn(null, socket); + }); + + // add HTTP server "request" listener + var gotReq = false; + server.once('request', function(req, res) { + gotReq = true; + res.end(); + }); + + var info = url.parse('http://127.0.0.1:' + port + '/foo'); + info.agent = agent; + http.get(info, function(res) { + res.socket.emit('free'); + assert.equal(true, res.socket.destroyed); + assert(gotReq); + done(); + }); + }); + + describe('PassthroughAgent', function() { it('should pass through to `http.globalAgent`', function(done) { // add HTTP server "request" listener |