1 | <?php |
||
8 | class TrustedProxyMiddleware implements HTTPMiddleware |
||
9 | { |
||
10 | |||
11 | private $trustedProxyIPs = null; |
||
12 | |||
13 | private $proxyHostHeaders = [ |
||
14 | 'X-Forwarded-Host' |
||
15 | ]; |
||
16 | |||
17 | private $proxyIPHeaders = [ |
||
18 | 'Client-IP', |
||
19 | 'X-Forwarded-For' |
||
20 | ]; |
||
21 | |||
22 | private $proxySchemeHeaders = [ |
||
23 | 'X-Forwarded-Protocol', |
||
24 | 'X-Forwarded-Proto', |
||
25 | ]; |
||
26 | |||
27 | public function getTrustedProxyIPs() |
||
31 | |||
32 | public function setTrustedProxyIPs($trustedProxyIPs) |
||
36 | |||
37 | public function getProxyHostHeaders() |
||
41 | |||
42 | public function setProxyHostHeaders($proxyHostHeaders) |
||
46 | |||
47 | public function getProxyIPHeaders() |
||
51 | |||
52 | public function setProxyIPHeaders($proxyIPHeaders) |
||
56 | |||
57 | public function getProxySchemeHeaders() |
||
61 | |||
62 | public function setProxySchemeHeaders($proxySchemeHeaders) |
||
66 | |||
67 | public function process(HTTPRequest $request, callable $delegate) |
||
101 | |||
102 | /** |
||
103 | * Determine if the current request is coming from a trusted proxy |
||
104 | * |
||
105 | * @return boolean True if the request's source IP is a trusted proxy |
||
106 | */ |
||
107 | protected function isTrustedProxy($request) |
||
126 | |||
127 | /** |
||
128 | * Extract an IP address from a header value that has been obtained. |
||
129 | * Accepts single IP or comma separated string of IPs |
||
130 | * |
||
131 | * @param string $headerValue The value from a trusted header |
||
132 | * @return string The IP address |
||
133 | */ |
||
134 | protected function getIPFromHeaderValue($headerValue) |
||
151 | } |
||
152 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: