class TrustedProxyMiddleware implements HTTPMiddleware (View source)

This middleware will rewrite headers that provide IP and host details from an upstream proxy.

Methods

public
string
getTrustedProxyIPs()

Return the comma-separated list of IP ranges that are trusted to provide proxy headers Can also be 'none' or '*' (all)

public
$this
setTrustedProxyIPs(string $trustedProxyIPs)

Set the comma-separated list of IP ranges that are trusted to provide proxy headers Can also be 'none' or '*' (all)

public
array
getProxyHostHeaders()

Return the array of headers from which to lookup the hostname

public
$this
setProxyHostHeaders(array $proxyHostHeaders)

Set the array of headers from which to lookup the hostname.

public
array
getProxyIPHeaders()

Return the array of headers from which to lookup the client IP

public
$this
setProxyIPHeaders(array $proxyIPHeaders)

Set the array of headers from which to lookup the client IP.

public
array
getProxySchemeHeaders()

Return the array of headers from which to lookup the client scheme (http/https)

public
$this
setProxySchemeHeaders(array $proxySchemeHeaders)

Set array of headers from which to lookup the client scheme (http/https) Can also specify comma-separated list as a single string.

public
process(HTTPRequest $request, callable $delegate)

Generate response for the given request

protected
bool
isTrustedProxy(HTTPRequest $request)

Determine if the current request is coming from a trusted proxy

protected
string
getIPFromHeaderValue(string $headerValue)

Extract an IP address from a header value that has been obtained.

Details

string getTrustedProxyIPs()

Return the comma-separated list of IP ranges that are trusted to provide proxy headers Can also be 'none' or '*' (all)

Return Value

string

$this setTrustedProxyIPs(string $trustedProxyIPs)

Set the comma-separated list of IP ranges that are trusted to provide proxy headers Can also be 'none' or '*' (all)

Parameters

string $trustedProxyIPs

Return Value

$this

array getProxyHostHeaders()

Return the array of headers from which to lookup the hostname

Return Value

array

$this setProxyHostHeaders(array $proxyHostHeaders)

Set the array of headers from which to lookup the hostname.

Parameters

array $proxyHostHeaders

Return Value

$this

array getProxyIPHeaders()

Return the array of headers from which to lookup the client IP

Return Value

array

$this setProxyIPHeaders(array $proxyIPHeaders)

Set the array of headers from which to lookup the client IP.

Parameters

array $proxyIPHeaders

Return Value

$this

array getProxySchemeHeaders()

Return the array of headers from which to lookup the client scheme (http/https)

Return Value

array

$this setProxySchemeHeaders(array $proxySchemeHeaders)

Set array of headers from which to lookup the client scheme (http/https) Can also specify comma-separated list as a single string.

Parameters

array $proxySchemeHeaders

Return Value

$this

HTTPResponse process(HTTPRequest $request, callable $delegate)

Generate response for the given request

Parameters

HTTPRequest $request
callable $delegate

Return Value

HTTPResponse

protected bool isTrustedProxy(HTTPRequest $request)

Determine if the current request is coming from a trusted proxy

Parameters

HTTPRequest $request

Return Value

bool

True if the request's source IP is a trusted proxy

protected string getIPFromHeaderValue(string $headerValue)

Extract an IP address from a header value that has been obtained.

Accepts single IP or comma separated string of IPs

Parameters

string $headerValue

The value from a trusted header

Return Value

string

The IP address