Created
December 21, 2010 22:57
-
-
Save mxey/750763 to your computer and use it in GitHub Desktop.
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 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