不会填充 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

将标头转换为环境变量比 之前通过以下方式缓解一些可能的跨站点脚本攻击 标头注入。标题包含无效字符(包括 下划线(现在以静默方式删除。

https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/?highlight=disappearing%20http%20headers#missing-disappearing-http-headers

如果您没有明确设置underscores_in_headers;,NGINX 将 静默删除带有下划线的 HTTP 标头(这是完全有效的 根据HTTP标准(。这样做是为了防止 将标题作为短划线和 CGI 变量映射到 CGI 变量时的歧义 在此过程中,下划线将映射到下划线。

最新更新