Created
May 11, 2016 16:15
-
-
Save tommybananas/010a01e3fef67b9e5dc436836da885e4 to your computer and use it in GitHub Desktop.
http-proxy socks agent test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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