Skip to content

Commit 83440f8

Browse files
gunnarliumweaverryan
authored andcommitted
Use static Request methods in Trusting Proxies doc
As these methods manipulate static properties, it makes sense to use the static methods. This also means that we don't need to create a throwaway Request instance just to set the trusted proxies.
1 parent 3205bbd commit 83440f8

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

components/http_foundation/trusting_proxies.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ your proxy.
2222
2323
use Symfony\Component\HttpFoundation\Request;
2424
25-
$request = Request::createFromGlobals();
26-
2725
// only trust proxy headers coming from this IP addresses
28-
$request->setTrustedProxies(array('192.0.0.1', '10.0.0.0/8'));
26+
Request::setTrustedProxies(array('192.0.0.1', '10.0.0.0/8'));
2927
3028
Configuring Header Names
3129
------------------------
@@ -40,10 +38,10 @@ By default, the following proxy headers are trusted:
4038
If your reverse proxy uses a different header name for any of these, you
4139
can configure that header name via :method:`Symfony\\Component\\HttpFoundation\\Request::setTrustedHeaderName`::
4240

43-
$request->setTrustedHeaderName(Request::HEADER_CLIENT_IP, 'X-Proxy-For');
44-
$request->setTrustedHeaderName(Request::HEADER_CLIENT_HOST, 'X-Proxy-Host');
45-
$request->setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'X-Proxy-Port');
46-
$request->setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X-Proxy-Proto');
41+
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, 'X-Proxy-For');
42+
Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, 'X-Proxy-Host');
43+
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'X-Proxy-Port');
44+
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X-Proxy-Proto');
4745

4846
Not trusting certain Headers
4947
----------------------------
@@ -53,4 +51,4 @@ listed above are trusted. If you need to trust some of these headers but
5351
not others, you can do that as well::
5452

5553
// disables trusting the ``X-Forwarded-Proto`` header, the default header is used
56-
$request->setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, '');
54+
Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, '');

0 commit comments

Comments
 (0)