node.js - 我是否成功更改了禁止的 http 标头?
问题描述
根据此页面:https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name,我不应该能够以编程方式更改禁止的 http 标头。例如,诸如“Origin”之类的禁止标头。
我有这个 Node.JS 代码:
router.get('/', function(req, res, next) {
try {
console.log('entry point');
const res2 = request.post({
url: 'http://localhost:3000/test',
headers: {'Origin': "Lol"}
});
console.log({res2: res2});
res.status(200).json({res2: res2});
} catch (error) {
console.error(error);
}
});
你可以看到我肯定将“Origin”标题设置为“Lol”值。
所以我的期望是:一个错误,我的中间件默认设置的另一个值或其他东西,但无论如何,当我打印 req 对象时,我不应该得到'lol'值(对吗?)。
实际输出:
{
"res2":{
"uri":{
"protocol":"http:",
"slashes":true,
"auth":null,
"host":"localhost:3000",
"port":"3000",
"hostname":"localhost",
"hash":null,
"search":null,
"query":null,
"pathname":"/test",
"path":"/test",
"href":"http://localhost:3000/test"
},
"method":"POST",
"headers":{
"Origin":"Lol",
"host":"localhost:3000"
}
}
}
您可以看到值是“Lol”,这与预期的不同。
所以我肯定错过了一些东西。你们 IT 人员知道它可能是什么吗?
在此先感谢您的帮助。
解决方案
正如@Adam Leblanc 在评论中所说:我的NodeJS 应用程序是发送请求的“用户代理”,这意味着它是“所有者”。所以它可以很容易地用任何东西来评估'Origin'标题。
这是一个菜鸟问题,但我相信我们都是从新手开始的。感谢您的回答亚当。
推荐阅读
- heroku - 在 Heroku 发布期间删除数据库列而不引发异常
- r - R:使用 addResourcePath 渲染本地传单图块
- python - 如何仅从 pandas datareader 获取工作日数据?
- git - ssh 密钥 github 添加仍然询问用户/密码
- c# - 如何在不显式调用派生的情况下创建基于派生类的 ctor 参数的对象
- c++ - C++“系统(命令)”在 NetBeans / Windows 上不起作用
- python - 使用 QPolygonF 绘图时如何在 QGraphicsPolygonItem 中添加文本?
- c++ - 第二次在图上运行时,广度/深度优先搜索导致崩溃
- mongodb - 如何在 Mongoose 上检索本周的数据?
- javascript - Chrome 扩展 VueJS:如何在网页上创建覆盖?