Skip to content

vlakoff/rka-scheme-and-host-detection-middleware

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proxy Scheme and Host detection middleware

Build status

PSR-7 Middleware that determines the scheme and host from the 'X-Forwarded-Proto' and 'X-Forwarded-Host' 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 akrabat/rka-scheme-and-host-detection-middleware

Usage

In Slim 3:

$trustedProxies = ['10.0.0.1', '10.0.0.2'];
$app->add(new RKA\Middleware\SchemeAndHost($trustedProxies));

$app->get('/', function ($request, $response, $args) {
    $scheme = $request->getUri()->getScheme();
    $host = $request->getUri()->getHost();

    return $response;
});

Testing

  • Code coverage: $ vendor/bin/phpcs
  • Unit tests: $ vendor/bin/phpunit
  • Code coverage: $ vendor/bin/phpunit --coverage-html ./build

About

PSR-7 middleware to detect scheme and host from proxy headers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%