semhoun/proxy-detection-middleware
最新稳定版本:0.5
Composer 安装命令:
composer require semhoun/proxy-detection-middleware
包简介
PSR-7 Middleware that determines the scheme, host and port from the 'X-Forwarded-Proto', 'X-Forwarded-Host' and 'X-Forwarded-Port' headers and updates the Request's Uri object.
关键字:
README 文档
README
PSR-7 Middleware that determines the scheme, host and port from the 'X-Forwarded-Proto', 'X-Forwarded-Host' and 'X-Forwarded-Port' headers and updates the Request's Uri object.
You can set a list of proxies that are trusted as the second constructor parameter. If this list is set, then the proxy headers will only be checked if the REMOTE_ADDR is in the trusted list.
Installation
composer require semhoun/proxy-detection-middleware
Usage
In Slim 4:
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\RequestHandlerInterface as RequestHandler; use Slim\Factory\AppFactory; use Slim\Psr7\Response; require __DIR__ . '/../vendor/autoload.php'; $app = AppFactory::create(); $trustedProxies = ['10.0.0.1', '10.0.0.2', '192.168.0.0/24']; $app->add(new RKA\Middleware\ProxyDetection($trustedProxies)); $app->get('/', function (Request $request, Response $response, $args) { $scheme = $request->getUri()->getScheme(); $host = $request->getUri()->getHost(); $port = $request->getUri()->getPort(); $response->getBody()->write('Real URI is ' . $scheme . '://' . $host . ':' . $port); return $response; }); $app->run();
Testing
- Code coverage:
$ vendor/bin/phpcs - Unit tests:
$ vendor/bin/phpunit
统计信息
- 总下载量: 2.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2020-12-30