From f4df03a1ed1ce14c3c7e36a968312597d54a6e5d Mon Sep 17 00:00:00 2001 From: hashexclude <42849803+hashexclude@users.noreply.github.com> Date: Thu, 19 Sep 2019 13:56:31 -0400 Subject: [PATCH] Adding Response to TunnelingAgent class. The content of response were not accessible outside the onConnect() function. Now the response object is exposed for use outside the limited scope. for e.g. now we can access the Proxy headers from the request library when needed using. ``` response.request._tunnel.request.agent.response.headers``` --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 3ee9abc..8a5996b 100644 --- a/index.js +++ b/index.js @@ -52,6 +52,7 @@ function TunnelingAgent(options) { self.maxSockets = self.options.maxSockets || http.Agent.defaultMaxSockets self.requests = [] self.sockets = [] + self.response = null self.on('free', function onFree(socket, host, port) { for (var i = 0, len = self.requests.length; i < len; ++i) { @@ -155,7 +156,8 @@ TunnelingAgent.prototype.createSocket = function createSocket(options, cb) { function onConnect(res, socket, head) { connectReq.removeAllListeners() socket.removeAllListeners() - + self.response = res + if (res.statusCode === 200) { assert.equal(head.length, 0) debug('tunneling connection has established')