semhoun / proxy-detection-middleware
This package is abandoned and no longer maintained.
The author suggests using the https://github.com/akrabat/proxy-detection-middleware package instead.
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.
0.5
2020-12-30 18:22 UTC
Requires
- php: ^7.2 || ^8.0
- psr/http-message: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- laminas/laminas-diactoros: ^2.3
- middlewares/utils: ^3.0
- oscarotero/php-cs-fixer-config: ^1.0
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^8|^9
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-08-30 07:02:43 UTC
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