Socket
Socket
Sign inDemoInstall

socks-proxy-agent

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socks-proxy-agent - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

.travis.yml

14

History.md

@@ -0,5 +1,15 @@

0.1.0 / 2013-11-19
==================
* add .travis.yml file
* socks-proxy-agent: properly mix in the proxy options
* socks-proxy-agent: coerce the `secureEndpoint` into a Boolean
* socks-proxy-agent: use "extend" module
* socks-proxy-agent: update to "agent-base" v1 API
0.0.2 / 2013-07-24
==================
- socks-proxy-agent: properly set the `defaultPort` property
* socks-proxy-agent: properly set the `defaultPort` property

@@ -9,2 +19,2 @@ 0.0.1 / 2013-07-11

- Initial release
* Initial release

7

package.json
{
"name": "socks-proxy-agent",
"version": "0.0.2",
"version": "0.1.0",
"description": "A SOCKS (v4a) proxy `http.Agent` implementation for HTTP and HTTPS",

@@ -28,4 +28,5 @@ "main": "socks-proxy-agent.js",

"dependencies": {
"agent-base": "~0.0.1",
"rainbowsocks": "~0.1.0"
"agent-base": "~1.0.1",
"rainbowsocks": "~0.1.0",
"extend": "~1.2.0"
},

@@ -32,0 +33,0 @@ "devDependencies": {

socks-proxy-agent
================
### A SOCKS (v4a) proxy `http.Agent` implementation for HTTP and HTTPS
[![Build Status](https://travis-ci.org/TooTallNate/node-socks-proxy-agent.png?branch=master)](https://travis-ci.org/TooTallNate/node-socks-proxy-agent)

@@ -9,2 +10,5 @@ This module provides an `http.Agent` implementation that connects to a specified

It can also be used in conjunction with the `ws` module to establish a WebSocket
connection over a SOCKS proxy. See the "Examples" section below.
Installation

@@ -20,6 +24,6 @@ ------------

Example
-------
Examples
--------
`http` module example:
#### `http` module example

@@ -50,3 +54,3 @@ ``` js

`https` module example:
#### `https` module example

@@ -78,2 +82,33 @@ ``` js

#### `ws` WebSocket connection example
``` js
var WebSocket = require('ws');
var SocksProxyAgent = require('socks-proxy-agent');
// SOCKS proxy to connect to
var proxy = process.env.socks_proxy || 'socks://127.0.0.1:9050';
console.log('using proxy server %j', proxy);
// WebSocket endpoint for the proxy to connect to
var endpoint = process.argv[2] || 'ws://echo.websocket.org';
console.log('attempting to connect to WebSocket %j', endpoint);
// create an instance of the `SocksProxyAgent` class with the proxy server information
var agent = new SocksProxyAgent(proxy);
// initiate the WebSocket connection
var socket = new WebSocket(endpoint, { agent: agent });
socket.on('open', function () {
console.log('"open" event!');
socket.send('hello world');
});
socket.on('message', function (data, flags) {
console.log('"message" event! %j %j', data, flags);
socket.close();
});
```
License

@@ -80,0 +115,0 @@ -------

@@ -8,2 +8,3 @@

var url = require('url');
var extend = require('extend');
var Agent = require('agent-base');

@@ -29,13 +30,18 @@ var RainbowSocks = require('rainbowsocks');

if (!opts) throw new Error('a SOCKS proxy server `host` and `port` must be specified!');
var proxy = clone(opts, {});
Agent.call(this);
Agent.call(this, connect);
// if `true` is passed for `secure` the the socket will be upgraded
// to a TLS socket before the HTTP request is written to it
this.secure = !!secure;
var proxy = extend({}, opts);
// prefer `hostname` over `host`, and set the `port` if needed
// If `true` is passed for `secureEndpoint` the the socket will be
// upgraded to a TLS socket before the HTTP request is written to it.
// Defaults to `false`
this.secureEndpoint = Boolean(secure || opts.secureEndpoint || false);
// prefer `hostname` over `host`, because of `url.parse()`
proxy.host = proxy.hostname || proxy.host;
proxy.port = +proxy.port || this.defaultPort;
// SOCKS doesn't *technically* have a default port, but this is
// the same default that `curl(1)` uses
proxy.port = +proxy.port || 1080;
if (proxy.host && proxy.path) {

@@ -46,2 +52,3 @@ // if both a `host` and `path` are specified then it's most likely the

delete proxy.path;
delete proxy.pathname;
}

@@ -54,29 +61,45 @@

/**
* Default port to connect to.
* Default options for the "connect" opts object.
*/
SocksProxyAgent.prototype.defaultPort = 1080;
var defaults = { port: 80 };
var secureDefaults = { port: 443 };
/**
* Initiates a SOCKS connection to the specified SOCKS proxy server, which in turn
* connects to the specified remote host and port.
* Initiates a SOCKS connection to the specified SOCKS proxy server,
* which in turn connects to the specified remote host and port.
*
* @api protected
* @api public
*/
SocksProxyAgent.prototype.createConnection = function (opts, fn) {
var secure = this.secure;
var proxy = new RainbowSocks(this.proxy.port, this.proxy.host);
proxy.once('connect', function (err) {
function connect (req, _opts, fn) {
var proxy = this.proxy;
var secureEndpoint = this.secureEndpoint;
// these `opts` are the connect options to connect to the destination endpoint
// XXX: we mix in the proxy options so that TLS options like
// `rejectUnauthorized` get passed to the destination endpoint as well
var proxyOpts = extend({}, proxy);
delete proxyOpts.host;
delete proxyOpts.hostname;
delete proxyOpts.port;
var opts = extend({}, proxyOpts, secureEndpoint ? secureDefaults : defaults, _opts);
var socks = new RainbowSocks(proxy.port, proxy.host);
socks.once('connect', function (err) {
if (err) return fn(err);
proxy.connect(opts.host, opts.port, function (err, socket) {
socks.connect(opts.host, opts.port, function (err, socket) {
if (err) return fn(err);
var s = socket;
if (secure) {
// upgrade to TLS first!
if (secureEndpoint) {
// since the proxy is connecting to an SSL server, we have
// to upgrade this socket connection to an SSL connection
if (!tls) tls = require('tls');
s = tls.connect({
servername: opts.host,
socket: socket
});
opts.socket = socket;
opts.servername = opts.host;
opts.host = null;
opts.hostname = null;
opts.port = null;
s = tls.connect(opts);
}

@@ -86,7 +109,2 @@ fn(null, s);

});
};
function clone (src, dest) {
for (var i in src) dest[i] = src[i];
return dest;
}

@@ -15,2 +15,4 @@

// adjusting the "slow" and "timeout" values because I run the
// tests against the Tor SOCKS proxy
this.slow(5000);

@@ -17,0 +19,0 @@ this.timeout(10000);

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