【发布时间】:2013-03-09 22:58:32
【问题描述】:
有没有办法检查使用 node/express 2.x 发送了哪些特定的标头?
我的文件下载在大多数情况下都能完美运行,但在某些特定情况下,我在 Chrome 中遇到错误(节点中没有错误):
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.
出于测试目的,我想查看是否已发送特定标头,有没有办法使用 node.js 执行此操作?
...而且因为有人会问我用于设置标头的代码,所以我将流作为下载流,并且只在一个位置设置标头。
res.setHeader('Content-disposition', 'attachment; filename=' + filename)
res.setHeader('Content-Length', stats.size)
res.setHeader('Content-type', 'application/pdf')
stream.pipe(res)
【问题讨论】:
-
stream.pipe(res).on('end', function () {console.log(res.headers); });应该记录发送的标头,因为响应已结束。 -
好主意!当流结束时,我已经有了一些事件处理程序。经过一番调查,我发现信息存储在
res._headers你应该把它作为答案,我会接受它。
标签: node.js header stream express