socks-proxy-agent
Advanced tools
Comparing version 2.1.0 to 2.1.1
2.1.1 / 2017-06-13 | ||
================== | ||
* fix a bug where `close` would emit before `end` | ||
* use "raw-body" module for tests | ||
* prettier | ||
2.1.0 / 2017-05-24 | ||
@@ -3,0 +10,0 @@ ================== |
{ | ||
"name": "socks-proxy-agent", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "A SOCKS proxy `http.Agent` implementation for HTTP and HTTPS", | ||
@@ -34,4 +34,5 @@ "main": "socks-proxy-agent.js", | ||
"mocha": "2", | ||
"raw-body": "^2.2.0", | ||
"socksv5": "0.0.6" | ||
} | ||
} |
@@ -1,2 +0,1 @@ | ||
/** | ||
@@ -26,6 +25,9 @@ * Module dependencies. | ||
function SocksProxyAgent (opts) { | ||
function SocksProxyAgent(opts) { | ||
if (!(this instanceof SocksProxyAgent)) return new SocksProxyAgent(opts); | ||
if ('string' == typeof opts) opts = url.parse(opts); | ||
if (!opts) throw new Error('a SOCKS proxy server `host` and `port` must be specified!'); | ||
if (!opts) | ||
throw new Error( | ||
'a SOCKS proxy server `host` and `port` must be specified!' | ||
); | ||
Agent.call(this, connect); | ||
@@ -56,3 +58,3 @@ | ||
proxy.lookup = true; | ||
// pass through | ||
// pass through | ||
case 'socks4a:': | ||
@@ -63,3 +65,3 @@ proxy.version = 4; | ||
proxy.lookup = true; | ||
// pass through | ||
// pass through | ||
case 'socks:': // no version specified, default to 5h | ||
@@ -70,3 +72,5 @@ case 'socks5h:': | ||
default: | ||
throw new TypeError('A "socks" protocol must be specified! Got: ' + proxy.protocol); | ||
throw new TypeError( | ||
'A "socks" protocol must be specified! Got: ' + proxy.protocol | ||
); | ||
} | ||
@@ -76,3 +80,3 @@ | ||
var auth = proxy.auth.split(':'); | ||
proxy.authentication = {username: auth[0], password: auth[1]}; | ||
proxy.authentication = { username: auth[0], password: auth[1] }; | ||
proxy.userid = auth[0]; | ||
@@ -91,8 +95,7 @@ } | ||
function connect (req, opts, fn) { | ||
function connect(req, opts, fn) { | ||
var proxy = this.proxy; | ||
// called once the SOCKS proxy has connected to the specified remote endpoint | ||
function onhostconnect (err, socket) { | ||
function onhostconnect(err, socket) { | ||
if (err) return fn(err); | ||
@@ -110,4 +113,4 @@ var s = socket; | ||
s = tls.connect(opts); | ||
socket.resume(); | ||
} | ||
socket.resume(); | ||
fn(null, s); | ||
@@ -117,3 +120,3 @@ } | ||
// called for the `dns.lookup()` callback | ||
function onlookup (err, ip) { | ||
function onlookup(err, ip) { | ||
if (err) return fn(err); | ||
@@ -145,4 +148,4 @@ options.target.host = ip; | ||
// proxy hostname DNS resolution for "4a" and "5h" socks proxy servers | ||
onlookup(null, opts.host) | ||
onlookup(null, opts.host); | ||
} | ||
} |
@@ -12,2 +12,3 @@ | ||
var socks = require('socksv5'); | ||
var getRawBody = require('raw-body'); | ||
var SocksProxyAgent = require('../'); | ||
@@ -106,9 +107,5 @@ | ||
assert.equal(404, res.statusCode); | ||
var data = ''; | ||
res.setEncoding('utf8'); | ||
res.on('data', function (b) { | ||
data += b; | ||
}); | ||
res.on('end', function () { | ||
data = JSON.parse(data); | ||
getRawBody(res, 'utf8', function (err, buf) { | ||
if (err) return done(err); | ||
var data = JSON.parse(buf); | ||
assert.equal('bar', data.foo); | ||
@@ -138,9 +135,5 @@ done(); | ||
assert.equal(404, res.statusCode); | ||
var data = ''; | ||
res.setEncoding('utf8'); | ||
res.on('data', function (b) { | ||
data += b; | ||
}); | ||
res.on('end', function () { | ||
data = JSON.parse(data); | ||
getRawBody(res, 'utf8', function (err, buf) { | ||
if (err) return done(err); | ||
var data = JSON.parse(buf); | ||
assert.equal('bar', data.foo); | ||
@@ -147,0 +140,0 @@ done(); |
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
17397
3
253