better-https-proxy-agent
Advanced tools
Comparing version 1.0.3 to 1.0.4
61
index.js
@@ -72,3 +72,3 @@ 'use strict'; | ||
tlsSocket.once('error', (err) => { | ||
if (!stream.surrogateConnected) stream.emit('error', err); | ||
if (!stream.surrogateConnectedStream) stream.emit('error', err); | ||
}); | ||
@@ -110,5 +110,6 @@ | ||
stream.surrogateConnected = false; | ||
stream.surrogateConnectedStream = null; | ||
stream.surrogateTimeout = undefined; | ||
stream.surrogateSetKeepAliveCalls = []; | ||
stream.surrogateKeepAliveEnable = undefined; | ||
stream.surrogateKeepAliveDelay = undefined; | ||
stream.surrogateReffed = true; | ||
@@ -128,5 +129,11 @@ | ||
stream.setKeepAlive = function surrogateSetKeepAlive() { | ||
this.surrogateSetKeepAliveCalls.push(Array.from(arguments)); | ||
stream.setKeepAlive = function surrogateSetKeepAlive(enable, initialDelay) { | ||
if (typeof enable === 'boolean') { | ||
this.surrogateKeepAliveEnable = enable; | ||
} else { | ||
initialDelay = enable; | ||
} | ||
if (initialDelay) this.surrogateKeepAliveDelay = initialDelay; | ||
return this; | ||
@@ -169,6 +176,9 @@ }; | ||
Agent.prototype._connectSurrogateStream = function _connectSurrogateStream(stream, tlsSocket) { | ||
stream.surrogateConnected = true; | ||
stream.surrogateConnectedStream = tlsSocket; | ||
stream.setReadable(tlsSocket); | ||
stream.setWritable(tlsSocket); | ||
tlsSocket.surrogateStream = stream; | ||
tlsSocket.surrogateSeenEnd = false; | ||
/* | ||
@@ -182,5 +192,8 @@ * Apply 'buffered' side effects. | ||
stream.surrogateSetKeepAliveCalls.forEach((args) => { | ||
tlsSocket.setKeepAlive.apply(tlsSocket, args) | ||
}); | ||
if (typeof stream.surrogateKeepAliveEnable !== 'undefined') { | ||
tlsSocket.setKeepAlive(stream.surrogateKeepAliveEnable); | ||
} | ||
if (typeof stream.surrogateKeepAliveDelay !== 'undefined') { | ||
tlsSocket.setKeepAlive(stream.surrogateKeepAliveDelay); | ||
} | ||
@@ -194,3 +207,3 @@ if (!stream.surrogateReffed) tlsSocket.unref(); | ||
stream.setTimeout = function connectedSetTimeout(timeout, callback) { | ||
tlsSocket.setTimeout(timeout); | ||
this.surrogateConnectedStream.setTimeout(timeout); | ||
@@ -202,4 +215,4 @@ this.setTimeoutListener(timeout, callback); | ||
stream.setKeepAlive = function connectedSetKeepAlive() { | ||
tlsSocket.setKeepAlive.apply(tlsSocket, arguments) | ||
stream.setKeepAlive = function connectedSetKeepAlive(enable, initialDelay) { | ||
this.surrogateConnectedStream.setKeepAlive(enable, initialDelay); | ||
@@ -210,3 +223,3 @@ return this; | ||
stream.ref = function connectedRef() { | ||
tlsSocket.ref.apply(tlsSocket) | ||
this.surrogateConnectedStream.ref(); | ||
@@ -217,3 +230,3 @@ return this; | ||
stream.unref = function connectedUnef() { | ||
tlsSocket.unref.apply(tlsSocket) | ||
this.surrogateConnectedStream.unref(); | ||
@@ -228,3 +241,21 @@ return this; | ||
*/ | ||
tlsSocket.on('timeout', () => stream.emit('timeout')); | ||
tlsSocket.on('timeout', function onTimeout() { | ||
this.surrogateStream.emit('timeout') | ||
}); | ||
/* | ||
* Although the 'duplexify' documentation states, "If the readable or | ||
* writable streams emits an error or close it will destroy both streams and | ||
* bubble up the event," on careful examination, `close` events only bubble | ||
* up and destroy the stream if they are 'premature', which means they occur | ||
* before an expected `end` event; `close` events are also emitted by the | ||
* 'duplexify' stream following an error. However, following an 'end' event, | ||
* no 'close' is emitted at all. Oops. We work around that problem here. | ||
*/ | ||
tlsSocket.once('end', function connectedOnEnd() { | ||
this.surrogateSeenEnd = true; | ||
}); | ||
tlsSocket.once('close', function connectedOnClose() { | ||
if (this.surrogateSeenEnd) this.surrogateStream.emit('close'); | ||
}); | ||
}; | ||
@@ -231,0 +262,0 @@ |
{ | ||
"name": "better-https-proxy-agent", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "An agent for HTTPS through an HTTP(S) proxy server using the CONNECT method", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "mocha test/test.js" | ||
"test": "mocha --expose-gc test/test.js" | ||
}, | ||
@@ -13,0 +13,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14162
203