I use express as my server and request to receive content from a window with a stream.
I have this very simple function for streaming data from a stream up to a client:
function(req, res){ request("http://example.com").pipe(res); }
The upstream field returns the Cache-Control: no-cache header, which I would like to change, so that Nginx (reverse proxy) can cache the response.
Where should I put res.header('Cache-Control', 60); ?
I tried:
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); }
But this causes an Error: Can't set headers after they are sent .
Is there a listener that starts when headers are sent, but before writeHeader() is writeHeader() ?
alexcline
source share