title: Express + Request Changing headers mid-stream
body: <p>I'm using express as my server and request to retrieve content from an up-stream box.</p>
  
  <p>I've got this beautifully simple function to stream data from the up-stream to the client:</p>
  
  <pre><code>function(req, res){
    request("http://example.com").pipe(res);
  }
  </code></pre>
  
  <p>The upstream box is returning a cache header <code>Cache-Control: no-cache</code> that I'd like to modify, so that Nginx (reverse proxy) can cache the response.</p>
  
  <p>Where should I put the <code>res.header('Cache-Control', 60);</code>?</p>
  
  <p>I've tried:</p>
  
  <pre><code>function(req, res){
    var retrieve = request("http://example.com");
    retrieve.on('data', function(chunk){
      if(res.get('Cache-Control') != 60)
        res.header('Cache-Control', 60);
    });
    retrieve.pipe(res);
  }
  </code></pre>
  
  <p>But this throws a <code>Error: Can't set headers after they are sent</code> error.</p>
  
  <p>Is there a listener that fires when the headers are sent, but before <code>writeHeader()</code> is called?</p>