-
-
Save image72/7aefb0f8c1c5bbba69a6758034a1e0fd to your computer and use it in GitHub Desktop.
Simple HTTP proxy for Node.js v0.10.x
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'); | |
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