Skip to content

Instantly share code, notes, and snippets.

@ithinkihaveacat
Created February 13, 2011 16:23
Show Gist options
  • Save ithinkihaveacat/824818 to your computer and use it in GitHub Desktop.
Save ithinkihaveacat/824818 to your computer and use it in GitHub Desktop.
var http = require('http');
var url = require('url');
http.createServer(function (req1, res1) {
var tmp = url.parse(req1.url);
var options = {
"host": tmp.hostname,
"port": tmp.port || 80,
"path": tmp.pathname + (tmp.search ? tmp.search : ''),
"method": req1.method,
"headers": req1.headers
};
var req2 = http.request(options, function (res2) {
res1.writeHead(res2.statusCode, res2.headers);
res2.on('data', function (chunk) {
res1.write(chunk);
});
res2.on('end', function () {
res1.end();
});
});
req1.on('data', function (chunk) {
req2.write(chunk);
});
req1.on('end', function () {
console.log(req1.method + " " + req1.url);
req2.end();
});
}).listen(8081);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment