Proxy Middleware 1.0 has been released. The package contains proxy related middleware classes that implement PSR-15:
They were extracted from Yii Middleware package.
TrustedHeaderProtocolResolver
Trusted header protocol resolver sets a server request protocol based on special header you trust
such as X-Forwarded-Proto
.
You can use it if your server is behind a trusted load balancer or a proxy that's always setting the special header itself discarding any header values provided by user.
TrustedHostsNetworkResolver
Scans the entire connection chain and resolves the data from forwarded headers taking into account trusted IPs. Additionally, all items' structure is thoroughly validated because headers' data can't be trusted. The following data is resolved:
- IP.
- Protocol
- Host.
- Port.
- IP identifier - unknown or
obfuscated. Used with
Forwarded
RFC header.
For forwarded headers it's possible to use both Forwarded
header standardized by RFC 7239 and groups of headers providing data separately.
The typical use case is having an application behind a load balancer.
The code coverage and MSI are close to 100%, static analysis meets the requirements of Psalm level 1.