Skip to content

Instantly share code, notes, and snippets.

@kfox
Created July 18, 2013 21:43
Show Gist options
  • Save kfox/6033396 to your computer and use it in GitHub Desktop.
Save kfox/6033396 to your computer and use it in GitHub Desktop.
Simple HTTP proxy for Node.js v0.10.x
var http = require('http');
var host = process.argv[2] || '127.0.0.1';
var port = process.argv[3] || 8080;
http.createServer( function (req, res) {
var proxy = http.request(req.url, function (proxy_res) {
proxy_res.on('data', function (chunk) {
res.write(chunk, 'binary');
});
proxy_res.on('end', function() {
res.end();
});
res.writeHead(proxy_res.statusCode, proxy_res.headers);
});
req.on('data', function (chunk) {
proxy.write(chunk, 'binary');
});
req.on('end', function () {
proxy.end();
});
}).listen(port, host);
console.log("proxy listening on %s:%d", host, port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment