Skip to content

Instantly share code, notes, and snippets.

@paul-english
Created February 25, 2011 03:46
Show Gist options
  • Save paul-english/843333 to your computer and use it in GitHub Desktop.
Save paul-english/843333 to your computer and use it in GitHub Desktop.
var http = require('http');
http.createServer(function(request, response) {
var proxy = http.createClient(80, 'google.com');
var url = request.url;
console.log(url);
var proxy_request = proxy.request(request.method, url, request.headers);
proxy_request.addListener('response', function (proxy_response) {
proxy_response.addListener('data', function(chunk) {
response.write(chunk, 'binary');
});
proxy_response.addListener('end', function() {
response.end();
});
response.writeHead(proxy_response.statusCode, proxy_response.headers);
});
request.addListener('data', function(chunk) {
proxy_request.write(chunk, 'binary');
});
request.addListener('end', function() {
proxy_request.end();
});
}).listen(8011);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment