Skip to content

Instantly share code, notes, and snippets.

@mxey
Created December 21, 2010 22:57
Show Gist options
  • Select an option

  • Save mxey/750763 to your computer and use it in GitHub Desktop.

Select an option

Save mxey/750763 to your computer and use it in GitHub Desktop.
var http = require('http');
var url = require('url');
var pattern = /4chan\.org/i;
function respond_censored(res) {
res.writeHead(403)
res.write('Censored');
res.end();
}
http.createServer(function (req, res) {
var u = url.parse(req.url);
var c = http.createClient(u.port || 80, u.host);
console.log(req.method + ' ' + req.url);
p = (u.pathname || '/') + (u.search || '');
hdr = req.headers;
if (u.host.match(pattern)) {
return respond_censored(res);
}
hdr['host'] = u.host;
var creq = c.request(req.method, p, hdr);
req.on('data', function (chunk) {
creq.write(chunk, 'binary');
});
req.on('end', function () {
creq.end()
});
creq.on('response', function (cres) {
req.connection.on('close', function () {
cres.connection.destroy();
});
res.writeHead(cres.statusCode, 'foo', cres.headers);
cres.on('data', function (chunk) {
res.write(chunk, 'binary');
});
cres.on('end', function () {
res.end();
});
});
}).listen(8080, '127.0.0.1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment