今天我将 Laravel 升级到了 L5.6(更新了 Symfony 组件到 v4)。另外,根据官方 Laravel 5.6 升级指南,我也将 fideloper/proxy
包更新到了 4.0。
之后我开始遇到这个错误:Type error: Argument 2 passed to Symfony\Component\HttpFoundation\Request::setTrustedProxies() must be of the type integer, array given, called in /var/www/html/vendor/fideloper/proxy/src/TrustProxies.php on line 54
Symfony 4 的 Symfony\Component\HttpFoundation\Request::setTrustedProxies()
确实期望第二个参数为整数(位掩码):
/**
* Sets a list of trusted proxies.
*
* You should only list the reverse proxies that you manage directly.
*
* @param array $proxies A list of trusted proxies
* @param int $trustedHeaderSet A bit field of Request::HEADER_*, to set which headers to trust from your proxies
*
* @throws \InvalidArgumentException When $trustedHeaderSet is invalid
*/
public static function setTrustedProxies(array $proxies, int $trustedHeaderSet)
{
self::$trustedProxies = $proxies;
self::$trustedHeaderSet = $trustedHeaderSet;
}
而且fideloper/proxy
4.0确实会将一个数组传递给这个函数,而不是一个整数:
public function handle(Request $request, Closure $next)
{
$request::setTrustedProxies([], $this->getTrustedHeaderNames()); // Reset trusted proxies between requests
$this->setTrustedProxyIpAddresses($request);
return $next($request);
}
和
/**
* Retrieve trusted header name(s), falling back to defaults if config not set.
*
* @return array
*/
protected function getTrustedHeaderNames()
{
return $this->headers ?: $this->config->get('trustedproxy.headers');
}
所以我不知道这是fideloper/proxy
的bug还是我漏掉了什么?
composer install
-仍然存在同样的问题。请发布任何解决方案。 - Inigo