Skip to content

Instantly share code, notes, and snippets.

@tommybananas
Created May 11, 2016 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommybananas/010a01e3fef67b9e5dc436836da885e4 to your computer and use it in GitHub Desktop.
Save tommybananas/010a01e3fef67b9e5dc436836da885e4 to your computer and use it in GitHub Desktop.
http-proxy socks agent test
var http = require('http'),
httpProxy = require('http-proxy'),
SocksProxyAgent = require('socks-proxy-agent');
var socksagent = new SocksProxyAgent('socks://127.0.0.1:9050'); // hangs
var httpagent = new http.Agent(); // works great
var proxy = httpProxy.createServer({
target:'http://mnultimate.org',
'agent': httpagent
});
proxy.listen(1338);
proxy.on('error', function (err, req, res) {
res.writeHead(500, {
'Content-Type': 'text/plain'
});
res.end('Something went wrong. And we are reporting a custom error message.');
});
proxy.on('proxyRes', function (proxyRes, req, res) {
console.log('RAW Response from the target', JSON.stringify(proxyRes.headers, true, 2));
});
proxy.on('open', function (proxySocket) {
// listen for messages coming FROM the target here
proxySocket.on('data', function(data){
console.log(data);
});
});
proxy.on('close', function (res, socket, head) {
// view disconnected websocket connections
console.log('Client disconnected');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment