https-proxy-agent
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -0,1 +1,9 @@ | ||
0.0.2 / 2013-07-11 | ||
================== | ||
- test: add mocha tests | ||
- don't use `socket.ondata`, use the official API instead | ||
- throw an Error when no proxy info is given | ||
- add support for passing options to net/tls .connect() | ||
0.0.1 / 2013-07-09 | ||
@@ -2,0 +10,0 @@ ================== |
@@ -28,5 +28,20 @@ | ||
if ('string' == typeof opts) opts = url.parse(opts); | ||
if (!opts) throw new Error('an HTTP(S) proxy server `host` and `port` must be specified!'); | ||
var proxy = clone(opts, {}); | ||
Agent.call(this); | ||
this.proxy = opts; | ||
this.secure = this.proxy.protocol && this.proxy.protocol == 'https:'; | ||
this.secure = proxy.protocol && proxy.protocol == 'https:'; | ||
// prefer `hostname` over `host`, and set the `port` if needed | ||
proxy.host = proxy.hostname || proxy.host; | ||
proxy.port = +proxy.port || (this.secure ? 443 : 80); | ||
if (proxy.host && proxy.path) { | ||
// if both a `host` and `path` are specified then it's most likely the | ||
// result of a `url.parse()` call... we need to remove the `path` portion so | ||
// that `net.connect()` doesn't attempt to open that as a unix socket file. | ||
delete proxy.path; | ||
} | ||
this.proxy = proxy; | ||
} | ||
@@ -44,3 +59,3 @@ inherits(HttpsProxyAgent, Agent); | ||
* | ||
* @api public | ||
* @api protected | ||
*/ | ||
@@ -50,31 +65,43 @@ | ||
var socket; | ||
var info = { | ||
host: this.proxy.hostname || this.proxy.host, | ||
port: +this.proxy.port || (this.secure ? 443 : 80) | ||
}; | ||
if (this.secure) { | ||
socket = tls.connect(info); | ||
socket = tls.connect(this.proxy); | ||
} else { | ||
socket = net.connect(info); | ||
socket = net.connect(this.proxy); | ||
} | ||
var msg = 'CONNECT ' + opts.host + ':' + opts.port + ' HTTP/1.1\r\n' + | ||
'Host: ' + opts.host + ':' + opts.port + '\r\n' + | ||
'\r\n'; | ||
socket.write(msg); | ||
function read () { | ||
var b = socket.read(); | ||
if (b) ondata(b); | ||
else socket.once('readable', read); | ||
} | ||
socket.ondata = function (b, offset, length) { | ||
var buf = b.slice(offset, length); | ||
function ondata (b) { | ||
//console.log(b.length, b, b.toString()); | ||
// TODO: verify that the socket is properly connected, check response... | ||
socket.ondata = null; | ||
// since the proxy is connecting to an SSL server, we have | ||
// to upgrade this socket connection to an SSL connection | ||
socket = tls.connect({ | ||
var secure = tls.connect({ | ||
socket: socket, | ||
servername: opts.host | ||
}); | ||
fn(null, socket); | ||
}; | ||
fn(null, secure); | ||
} | ||
if (socket.read) { | ||
read(); | ||
} else { | ||
socket.once('data', ondata); | ||
} | ||
var msg = 'CONNECT ' + opts.host + ':' + opts.port + ' HTTP/1.1\r\n' + | ||
'Host: ' + opts.host + ':' + opts.port + '\r\n' + | ||
'\r\n'; | ||
socket.write(msg); | ||
}; | ||
function clone (src, dest) { | ||
for (var i in src) dest[i] = src[i]; | ||
return dest; | ||
} |
{ | ||
"name": "https-proxy-agent", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "An HTTP(s) proxy `http.Agent` implementation for HTTPS", | ||
@@ -5,0 +5,0 @@ "main": "https-proxy-agent.js", |
@@ -37,3 +37,3 @@ https-proxy-agent | ||
// create an instance of the `HttpsProxyAgent` class with the proxy server information | ||
var agent = new HttpProxyAgent(proxy); | ||
var agent = new HttpsProxyAgent(proxy); | ||
opts.agent = agent; | ||
@@ -40,0 +40,0 @@ |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances 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
7519
6
139
5
3