Skip to content

Instantly share code, notes, and snippets.

@ChrisRicca
Created May 23, 2010 04:41
Show Gist options
  • Select an option

  • Save ChrisRicca/410647 to your computer and use it in GitHub Desktop.

Select an option

Save ChrisRicca/410647 to your computer and use it in GitHub Desktop.

Revisions

  1. ChrisRicca revised this gist May 23, 2010. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions node-js-demo-proxy.js
    Original file line number Diff line number Diff line change
    @@ -12,12 +12,12 @@ http.createServer(function (req, res) {
    var request = google.request('GET', req.url, {'host': 'www.google.com'});

    request.addListener('response', function (response) {
    res.writeHead(response.statusCode, response.headers);
    res.writeHead(response.statusCode, response.headers);

    response.addListener('data', function (chunk) {
    response.addListener('data', function (chunk) {
    sys.puts(this_count + " DATA!");
    res.write(chunk);
    });
    });

    response.addListener('end', function (chunk) {
    sys.puts(this_count + " END!");
  2. ChrisRicca created this gist May 23, 2010.
    32 changes: 32 additions & 0 deletions node-js-demo-proxy.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    sys = require('sys'),
    http = require('http');

    request_count = 1;

    http.createServer(function (req, res) {
    var this_count = "(" + request_count++ + ")";

    sys.puts(this_count + " REQUESTED! " + req.url);

    var google = http.createClient(80, 'www.google.com');
    var request = google.request('GET', req.url, {'host': 'www.google.com'});

    request.addListener('response', function (response) {
    res.writeHead(response.statusCode, response.headers);

    response.addListener('data', function (chunk) {
    sys.puts(this_count + " DATA!");
    res.write(chunk);
    });

    response.addListener('end', function (chunk) {
    sys.puts(this_count + " END!");
    res.end();
    });
    });

    request.end();

    }).listen(8000);

    sys.puts('Server running at http://127.0.0.1:8000/');