title: nodejs: node-http-proxy and harmon: rewriting the html response from the end point instead of the 302 redirected response.
body: <p>I'm using nodejs with <a href="https://github.com/nodejitsu/node-http-proxy" rel="nofollow">node-http-proxy</a> along with harmon. I am using harmon to rewrite the proxied response to include a javascript file and a css file. When I set the target of the proxy to be <a href="http://nodejs.org" rel="nofollow">http://nodejs.org</a> or anything other than localhost, I receive a 301 or 302 redirect. The script is rewriting the 301 response instead of the fully proxied response. How can I use harmon to rewrite the end response instead of the 302 response?</p>
  
  <p>Here is the example of the script I am running from the harmon example folder:</p>
  
  <pre><code>var http = require('http');
  var connect = require('connect');
  var httpProxy = require('http-proxy');
  
  var selects = [];
  var simpleselect = {};
  
  //&lt;img id="logo" src="/images/logo.svg" alt="node.js"&gt;
  simpleselect.query = 'img';
  simpleselect.func = function (node) {
  
  //Create a read/write stream wit the outer option 
  //so we get the full tag and we can replace it
  var stm = node.createStream({ "outer" : true });
  
  //variable to hold all the info from the data events
  var tag = '';
  
  //collect all the data in the stream
  stm.on('data', function(data) {
     tag += data;
  });
  
  //When the read side of the stream has ended..
  stm.on('end', function() {
  
    //Print out the tag you can also parse it or regex if you want
    process.stdout.write('tag:   ' + tag + '\n');
    process.stdout.write('end:   ' + node.name + '\n');
  
    //Now on the write side of the stream write some data using .end()
    //N.B. if end isn't called it will just hang.  
    stm.end('&lt;img id="logo" src="http://i.imgur.com/LKShxfc.gif"         alt="node.js"&gt;');      
  
    });     
   }
  
    selects.push(simpleselect);
  
   //
   // Basic Connect App
   //
   var app = connect();
  
   var proxy = httpProxy.createProxyServer({
     target: 'http://nodejs.org'
   })
  
  
   app.use(require('../')([], selects, true));
  
   app.use(
     function (req, res) {
      proxy.web(req, res);
     }
   );
  </code></pre>