title: Simple node.js proxy by piping http server to http request
body: <p>Trying to learn more about node.js by making a simple http proxy server. The use scenario is simple: user -> proxy -> server -> proxy -> user</p>
  
  <p>The following code works until the last step. Couldn't find way to pipe connector's output back to the user.</p>
  
  <pre><code>#!/usr/bin/env node
  
  var
      url = require('url'),
      http = require('http'),
      acceptor = http.createServer().listen(3128);
  
  acceptor.on('request', function(request, response) {
      console.log('request ' + request.url);
      request.pause();
      var options = url.parse(request.url);
      options.headers = request.headers;
      options.method = request.method;
      options.agent = false;
  
      var connector = http.request(options);
      request.pipe(connector);
      request.resume();
  //  connector.pipe(response); // doesn't work
  //  connector.pipe(request); // doesn't work either
  });
  </code></pre>
  
  <p>Using tcpflow I see the incoming request from the browser, then the outgoing proxy request, then the server response back to the proxy. Somehow i couldn't manage to retransmit the response back to the browser.</p>
  
  <p>What is the proper way to implement this logic with pipes?</p>