Skip to content

Instantly share code, notes, and snippets.

@Hafthor
Created August 17, 2011 20:33
Show Gist options
  • Save Hafthor/1152536 to your computer and use it in GitHub Desktop.
Save Hafthor/1152536 to your computer and use it in GitHub Desktop.
http relay using node.js
var http = require('http');
http.createServer(function (req, resp) {
var h = req.headers;
h.host = "stackoverflow.com";
var req2 = http.request({
host: h.host, port: 80, path: req.url, method: req.method, headers: h
}, function (resp2) {
resp.writeHead(resp2.statusCode, resp2.headers);
resp2.on('data', function (d) { resp.write(d); });
resp2.on('end', function () { resp.end(); });
});
req.on('data', function (d) { req2.write(d); });
req.on('end', function () { req2.end(); });
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/ echoing '+h.host);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment