A HTTP Proxy Server in 20 Lines of node.js Code

A HTTP Proxy Server in 20 Lines of node.js Code 

var http = require('http');

http.createServer(function(request, response) {
  var proxy = http.createClient(80, request.headers['host'])
  var proxy_request = proxy.request(request.method, request.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.writeHead(proxy_response.statusCode, proxy_response.headers);
  request.addListener('data', function(chunk) {
    proxy_request.write(chunk, 'binary');
  request.addListener('end', function() {

download link: proxy server written in node.js

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s