Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akrabat/proxy-detection-middleware
PSR-7 / PSR-15 middleware to detect scheme and host from proxy headers
https://github.com/akrabat/proxy-detection-middleware
Last synced: 3 months ago
JSON representation
PSR-7 / PSR-15 middleware to detect scheme and host from proxy headers
- Host: GitHub
- URL: https://github.com/akrabat/proxy-detection-middleware
- Owner: akrabat
- License: other
- Created: 2015-11-01T13:39:45.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2024-03-26T11:33:12.000Z (10 months ago)
- Last Synced: 2024-07-30T18:14:03.432Z (6 months ago)
- Language: PHP
- Homepage:
- Size: 51.8 KB
- Stars: 31
- Watchers: 6
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Proxy Scheme, Host and Port detection middleware
PSR-15 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 akrabat/proxy-detection-middleware`
## Usage
In Slim 3:
```php
$trustedProxies = ['10.0.0.1', '10.0.0.2'];
$app->add(new RKA\Middleware\ProxyDetection($trustedProxies));$app->get('/', function ($request, $response, $args) {
$scheme = $request->getUri()->getScheme();
$host = $request->getUri()->getHost();
$port = $request->getUri()->getPort();return $response;
});
```## Testing
* Code coverage: ``$ vendor/bin/phpcs``
* Unit tests: ``$ vendor/bin/phpunit``
* Code coverage: ``$ vendor/bin/phpunit --coverage-html ./build``[Master]: https://travis-ci.org/akrabat/rka-content-type-renderer
[Master image]: https://secure.travis-ci.org/akrabat/rka-content-type-renderer.svg?branch=master