Alb*_*elB 2 header stream node.js express
有没有办法检查使用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.
Run Code Online (Sandbox Code Playgroud)
出于测试目的,我想看看是否已发送特定标头,是否有办法使用node.js执行此操作?
...而且因为有人要问我关于我用来设置标题的代码,我正在下载一个流作为下载,并且只在一个地方设置标题.
res.setHeader('Content-disposition', 'attachment; filename=' + filename)
res.setHeader('Content-Length', stats.size)
res.setHeader('Content-type', 'application/pdf')
stream.pipe(res)
Run Code Online (Sandbox Code Playgroud)
HTTP响应是一个WritableStream.当流关闭时,会发出一个完成事件.因此听取它的诀窍是:
res.on('finish', function() {
console.log(res._headers);
});
Run Code Online (Sandbox Code Playgroud)
更加灵活.可以放在中间件或资源处理程序中.
| 归档时间: |
|
| 查看次数: |
1967 次 |
| 最近记录: |