Laravel自定义请求标头未填充

时间:2018-07-02 06:31:51

标签: 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”。

为什么不填充它们?

1 个答案:

答案 0 :(得分:1)

默认情况下,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设置为on,NGINX将   用下划线静默删除HTTP标头(这是完全有效的   根据HTTP标准)。这样做是为了防止   将标头映射到CGI变量时,如破折号和   下划线在该过程中被映射为下划线。