Ski*_*lef 19 php proxy laravel laravel-5.6
我今天已从L5.5升级到L5.6(在此过程中将Symfony组件更新为v4).此外,我fideloper/proxy还将官方Laravel 5.6升级指南更新到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;
}
Run Code Online (Sandbox Code Playgroud)
和fideloper/proxy4.0确实给出了一个阵列,而不是一个整数这个函数:
public function handle(Request $request, Closure $next)
{
$request::setTrustedProxies([], $this->getTrustedHeaderNames()); // Reset trusted proxies between requests
$this->setTrustedProxyIpAddresses($request);
return $next($request);
}
Run Code Online (Sandbox Code Playgroud)
和
/**
* 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');
}
Run Code Online (Sandbox Code Playgroud)
所以我无法理解这是否是错误,fideloper/proxy或者我只是遗漏了什么?
Ini*_*igo 23
经过一番调查(Winmerge与全新安装的Laravel 5.6进行比较)后,归结为文件的不同之处app\Http\Middleware\TrustProxies.php:
Laravel 5.5:
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array
*/
protected $proxies;
/**
* The current proxy header mappings.
*
* @var array
*/
protected $headers = [
Request::HEADER_FORWARDED => 'FORWARDED',
Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
];
}
Run Code Online (Sandbox Code Playgroud)
Laravel 5.6:
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array
*/
protected $proxies;
/**
* The headers that should be used to detect proxies.
*
* @var string
*/
protected $headers = Request::HEADER_X_FORWARDED_ALL;
}
Run Code Online (Sandbox Code Playgroud)
Ergo,protected $headers = Request::HEADER_X_FORWARDED_ALL;根据Laravel 5.6版本设置
aph*_*hoe 13
打开app\Http\Middleware\TrustProxies.php.
更改以下内容
protected $headers = [
Request::HEADER_FORWARDED => 'FORWARDED',
Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
];
Run Code Online (Sandbox Code Playgroud)
至
protected $headers = Request::HEADER_X_FORWARDED_ALL;
Run Code Online (Sandbox Code Playgroud)
小智 11
如升级指南中所述,您需要将App\Http\Middleware\TrustProxies中的$ headers属性设置为位属性.
常量在Symfony\Component\HttpFoundation\Request中定义.
const HEADER_FORWARDED = 0b00001; // When using RFC 7239
const HEADER_X_FORWARDED_FOR = 0b00010;
const HEADER_X_FORWARDED_HOST = 0b00100;
const HEADER_X_FORWARDED_PROTO = 0b01000;
const HEADER_X_FORWARDED_PORT = 0b10000;
const HEADER_X_FORWARDED_ALL = 0b11110; // All "X-Forwarded-*" headers
const HEADER_X_FORWARDED_AWS_ELB = 0b11010; // AWS ELB doesn't send X-Forwarded-Host
Run Code Online (Sandbox Code Playgroud)
在升级指南中,使用了HEADER_X_FORWARDED_ALL,但您可以使用位值的组合.
| 归档时间: |
|
| 查看次数: |
11039 次 |
| 最近记录: |