php - Laravel 自定义请求标头未填充
问题描述
我正在使用邮递员向我的项目发出请求,如下所示:
Request Headers:
cache-control:"no-cache"
postman-token:"65b35825-8c35-47ae-ad03-159d3da08e95"
partner_key:"123456789"
partner_secret:"123456789"
business_external_id:"123456789"
user-agent:"PostmanRuntime/6.4.1"
accept:"*/*"
host:"loyaltybro.local"
accept-encoding:"gzip, deflate"
我对“partner_key”、“partner_secret”、“business_external_id”感兴趣。
在我的代码中,我正在记录收到的标头,如下所示:
public function handle($request, Closure $next)
{
$headers = $request->headers->all();
\Log::info($headers);
...
}
这是日志输出。
local.INFO: array (
'cache-control' =>
array (
0 => 'no-cache',
),
'postman-token' =>
array (
0 => '65b35825-8c35-47ae-ad03-159d3da08e95',
),
'user-agent' =>
array (
0 => 'PostmanRuntime/6.4.1',
),
'accept' =>
array (
0 => '*/*',
),
'host' =>
array (
0 => 'loyaltybro.local',
),
'accept-encoding' =>
array (
0 => 'gzip, deflate',
),
'connection' =>
array (
0 => 'keep-alive',
),
)
没有“partner_key”、“partner_secret”、“business_external_id”。
为什么他们没有被填充?
解决方案
默认情况下,在 nginx 和 apache 中都会删除带有下划线的标头。
http://httpd.apache.org/docs/trunk/new_features_2_4.html
将标头转换为环境变量比以前更严格,以通过标头注入减轻一些可能的跨站点脚本攻击。包含无效字符(包括下划线)的标题现在被静默删除。
如果你没有明确地设置 underscores_in_headers on;,NGINX 将默默地丢弃带有下划线的 HTTP 标头(根据 HTTP 标准这是完全有效的)。这样做是为了防止在将标头映射到 CGI 变量时出现歧义,因为在该过程中,破折号和下划线都映射到下划线。
推荐阅读
- javascript - 在Node js中获取路由参数
- c++ - 使用递归反转并打印出数组的内容
- cpu-registers - 寄存器直接寻址模式的指令长度是多少?
- graphql - graphql中的嵌套内联片段
- java - 如何使用 TestNG/Selenium/Java 声明全局变量?
- php - 如何在 CodeIgniter 视图中显示数据?
- google-cloud-platform - 使用身份识别代理 (IAP) 从 Google Cloud Storage 存储桶提供内容
- python-3.x - python asyncio - 如何等待取消的屏蔽任务?
- swift - UICollectionView 上的 reloadData() 使用动态单元更改 contenteOffset
- python - Python if/else 语句混淆