Dropped.on.Caprica Dropped.on.Caprica - 3 months ago 10
Node.js Question

Is There a Way to Check Sent Headers with Node/ Express 2.x?

Is there a way of checking what specific headers have been sent using node/ express 2.x?

I have a file download that works perfectly most of the time, but in a few specific instances I get an error in Chrome (no errors in node):

Duplicate headers received from server
The response from the server contained duplicate headers. This problem is generally the result of a misconfigured website or proxy. Only the website or proxy administrator can fix this issue.
Error 349 (net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION): Multiple distinct Content-Disposition headers received. This is disallowed to protect against HTTP response splitting attacks.


For testing purposes, I'd like to see if a specific header has been sent or not, is there a way of doing this with node.js?




...And because someone's going to ask me about the code I use to set headers, I'm piping a stream as the download and are only setting headers in one spot.

res.setHeader('Content-disposition', 'attachment; filename=' + filename)
res.setHeader('Content-Length', stats.size)
res.setHeader('Content-type', 'application/pdf')

stream.pipe(res)

Answer

As @generalhenry stated on my question comments:

stream.pipe(res).on('end', function () {
  console.log(res._headers); 
});

The above line worked for me.

Comments