title: Node.js proxy for monitor network requests and responses
body: <p>I am using Nodejitsu's http proxy to build a tool to monitor web traffic.</p>
  
  <pre><code>httpProxy.createProxyServer({
      target: 'http://localhost:9000'
  })
  .listen(8000);
  
  util.puts('proxy server listening on port 8000');
  
  
  http.createServer(function targetServer(req, res) {
      res.writeHead(302, { 'Location': req.headers.host });
      util.puts('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
  
      res.end();
  
  })
  .listen(9000);
  
  util.puts('target server listening on port 9000');
  </code></pre>
  
  <p>What I want to do is</p>
  
  <ol>
  <li>Proxy outgoing requests from the client (browser) to my target server</li>
  <li>Send them to their original destination url from my target server</li>
  <li>Receive the response on my target server</li>
  <li>Send the response back to the client</li>
  </ol>
  
  <p>Basically have a middleman placed between the client and the destination server so i can monitor traffic. However when I try to do this, as soon as I make the 302 request, I get an <code>ECONN</code> error.</p>
  
  <pre><code>Error: connect ECONNREFUSED
      at errnoException (net.js:901:11)
      at Object.afterConnect [as oncomplete] (net.js:892:19)
  </code></pre>
  
  <p>Can anyone help me figure out whats going on</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I changed the 302 <code>Location</code> argument like so:</p>
  
  <pre><code>res.writeHead(302, { 'Location': '/' });
  </code></pre>
  
  <p>Now, when the browser tries hitting my proxy server, it enters a redirection loop. Why is this happening? </p>