Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

https-proxy-agent

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

https-proxy-agent - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

test/test.js

8

History.md

@@ -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 @@ ==================

67

https-proxy-agent.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc