NodeRED http-response 节点:如何停止 NodeRED 添加字符集到 content-type?

NodeRED http-response node: How to stop NodeRED adding charset to content-type?

我需要在 NodeRED 中为 jpeg 图像构建一个 http 代理。我的目标是浏览器确实从 NodeRED 服务器获取仪表板中的所有页面资源。并且图像只能从另一台服务器获得。

我试过这个抽象流程:

http-in -> http-request -> function node -> http response

在函数节点中我设置了headers:

msg.headers = {
    "content-type": "image/jpeg",
    "content-disposition": "inline; filename=\"myimage.jpg\""
}

问题是,浏览器获取这些 headers(摘录):

content-type: image/jpeg; charset=utf-8
content-disposition: inline; filename="myimage.jpg"

charset=utf-8 到底是从哪里来的,如何阻止 NodeRED 添加这个?

你没有在流程中提及 msg.payload 的设置。

如果您传递给 HTTP 响应节点的 msg.payload 是字符串,则内容类型会添加字符集参数。这不是 Node-RED 的故意行为 - 但在底层 http/express 框架中发生了某些事情。

如果msg.payload是Buffer对象,则不添加该参数。

charset=utf-8,由node-red添加来定义标准,如果headers在其上添加字符集就没有问题。