title: How to use transform stream using request?
body: <p>Basically, I would like to alter the http response before sending it to the client, using transform streams, but my code below throws an error : [Error: write after end].</p>
  
  <p>Documentation on <a href="http://nodejs.org/api/stream.html#stream_writable_end_chunk_encoding_callback" rel="noreferrer">http://nodejs.org/api/stream.html#stream_writable_end_chunk_encoding_callback</a> says :</p>
  
  <blockquote>
    <p>Calling write() after calling end() will raise an error.</p>
  </blockquote>
  
  <p>How can I prevent write() to be called after end() in this case ?</p>
  
  <pre><code>var request = require('request');
  var Transform = require('stream').Transform;
  var http = require('http');
  
  var parser = new Transform();
  parser._transform = function(data, encoding, done) {
    console.log(data);
    this.push(data);
    done();
  };
  
  parser.on('error', function(error) {
    console.log(error);
  });
  
  http.createServer(function (req, resp) {
    var dest = 'http://stackoverflow.com/';
    var x = request({url:dest, encoding:null})
  
    x.pipe(parser).pipe(resp)
  }).listen(8000);
  </code></pre>