【发布时间】:2019-11-15 13:07:22
【问题描述】:
我的 express 应用中有一个下载 GET 端点。现在它只是从文件系统中读取一个文件,并在设置一些头文件后将其流式传输。
当我在 Chrome 中打开端点时,我可以看到它被视为“文档”,而在 Firefox 中它被视为类型 png。
我似乎无法理解为什么会被区别对待。
Chrome:标题栏 - “下载” Firefox:标题栏 - “图像名称”
在 Chrome 中,如果我刷新地址栏,这也会导致不缓存图像。 在 Firefox 中,它被缓存得很好。
这是我的快递代码:
app.get("/download", function(req, res) {
let file = `${__dirname}/graph-colors.png`;
var mimetype = "image/png";
res.set("Content-Type", mimetype);
res.set("Cache-Control", "public, max-age=1000");
res.set("Content-Disposition", "inline");
res.set("Vary", "Origin");
var filestream = fs.createReadStream(file);
filestream.pipe(res);
});
还为浏览器网络选项卡附加图像。
【问题讨论】:
标签: node.js google-chrome express firefox caching