Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 96d031b

Browse filesBrowse files
committed
[HttpFoundation] remove deprecated features
1 parent 7263d77 commit 96d031b
Copy full SHA for 96d031b

File tree

3 files changed

+45
-243
lines changed
Filter options

3 files changed

+45
-243
lines changed

‎src/Symfony/Component/HttpFoundation/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/CHANGELOG.md
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
CHANGELOG
22
=========
33

4+
4.0.0
5+
-----
6+
7+
* the `Request::setTrustedHeaderName()` and `Request::getTrustedHeaderName()`
8+
methods have been removed
9+
* the `Request::HEADER_CLIENT_IP` constant has been removed, use
10+
`Request::HEADER_X_FORWARDED_FOR` instead
11+
* the `Request::HEADER_CLIENT_HOST` constant has been removed, use
12+
`Request::HEADER_X_FORWARDED_HOST` instead
13+
* the `Request::HEADER_CLIENT_PROTO` constant has been removed, use
14+
`Request::HEADER_X_FORWARDED_PROTO` instead
15+
* the `Request::HEADER_CLIENT_PORT` constant has been removed, use
16+
`Request::HEADER_X_FORWARDED_PORT` instead
17+
* checking for cacheable HTTP methods using the `Request::isMethodSafe()`
18+
method (by not passing `false` as its argument) is not supported anymore and
19+
throws a `\BadMethodCallException`
20+
421
3.3.0
522
-----
623

‎src/Symfony/Component/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+26-118Lines changed: 26 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ class Request
3838
const HEADER_X_FORWARDED_ALL = 0b11110; // All "X-Forwarded-*" headers
3939
const HEADER_X_FORWARDED_AWS_ELB = 0b11010; // AWS ELB doesn't send X-Forwarded-Host
4040

41-
/** @deprecated since version 3.3, to be removed in 4.0 */
42-
const HEADER_CLIENT_IP = self::HEADER_X_FORWARDED_FOR;
43-
/** @deprecated since version 3.3, to be removed in 4.0 */
44-
const HEADER_CLIENT_HOST = self::HEADER_X_FORWARDED_HOST;
45-
/** @deprecated since version 3.3, to be removed in 4.0 */
46-
const HEADER_CLIENT_PROTO = self::HEADER_X_FORWARDED_PROTO;
47-
/** @deprecated since version 3.3, to be removed in 4.0 */
48-
const HEADER_CLIENT_PORT = self::HEADER_X_FORWARDED_PORT;
49-
5041
const METHOD_HEAD = 'HEAD';
5142
const METHOD_GET = 'GET';
5243
const METHOD_POST = 'POST';
@@ -73,25 +64,6 @@ class Request
7364
*/
7465
protected static $trustedHosts = array();
7566

76-
/**
77-
* Names for headers that can be trusted when
78-
* using trusted proxies.
79-
*
80-
* The FORWARDED header is the standard as of rfc7239.
81-
*
82-
* The other headers are non-standard, but widely used
83-
* by popular reverse proxies (like Apache mod_proxy or Amazon EC2).
84-
*
85-
* @deprecated since version 3.3, to be removed in 4.0
86-
*/
87-
protected static $trustedHeaders = array(
88-
self::HEADER_FORWARDED => 'FORWARDED',
89-
self::HEADER_CLIENT_IP => 'X_FORWARDED_FOR',
90-
self::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST',
91-
self::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO',
92-
self::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT',
93-
);
94-
9567
protected static $httpMethodParameterOverride = false;
9668

9769
/**
@@ -226,22 +198,30 @@ class Request
226198

227199
private static $trustedHeaderSet = -1;
228200

229-
/** @deprecated since version 3.3, to be removed in 4.0 */
230-
private static $trustedHeaderNames = array(
231-
self::HEADER_FORWARDED => 'FORWARDED',
232-
self::HEADER_CLIENT_IP => 'X_FORWARDED_FOR',
233-
self::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST',
234-
self::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO',
235-
self::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT',
236-
);
237-
238201
private static $forwardedParams = array(
239202
self::HEADER_X_FORWARDED_FOR => 'for',
240203
self::HEADER_X_FORWARDED_HOST => 'host',
241204
self::HEADER_X_FORWARDED_PROTO => 'proto',
242205
self::HEADER_X_FORWARDED_PORT => 'host',
243206
);
244207

208+
/**
209+
* Names for headers that can be trusted when
210+
* using trusted proxies.
211+
*
212+
* The FORWARDED header is the standard as of rfc7239.
213+
*
214+
* The other headers are non-standard, but widely used
215+
* by popular reverse proxies (like Apache mod_proxy or Amazon EC2).
216+
*/
217+
private static $trustedHeaders = array(
218+
self::HEADER_FORWARDED => 'FORWARDED',
219+
self::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
220+
self::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
221+
self::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
222+
self::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
223+
);
224+
245225
/**
246226
* Constructor.
247227
*
@@ -572,19 +552,9 @@ public function overrideGlobals()
572552
*
573553
* @throws \InvalidArgumentException When $trustedHeaderSet is invalid
574554
*/
575-
public static function setTrustedProxies(array $proxies/*, int $trustedHeaderSet*/)
555+
public static function setTrustedProxies(array $proxies, int $trustedHeaderSet)
576556
{
577557
self::$trustedProxies = $proxies;
578-
579-
if (2 > func_num_args()) {
580-
// @deprecated code path in 3.3, to be replaced by mandatory argument in 4.0.
581-
throw new \InvalidArgumentException(sprintf('The %s() method expects a bit field of Request::HEADER_* as second argument. Defining it is required since version 3.3. See http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html for more info.', __METHOD__));
582-
}
583-
$trustedHeaderSet = func_get_arg(1);
584-
585-
foreach (self::$trustedHeaderNames as $header => $name) {
586-
self::$trustedHeaders[$header] = $header & $trustedHeaderSet ? $name : null;
587-
}
588558
self::$trustedHeaderSet = $trustedHeaderSet;
589559
}
590560

@@ -634,65 +604,6 @@ public static function getTrustedHosts()
634604
return self::$trustedHostPatterns;
635605
}
636606

637-
/**
638-
* Sets the name for trusted headers.
639-
*
640-
* The following header keys are supported:
641-
*
642-
* * Request::HEADER_CLIENT_IP: defaults to X-Forwarded-For (see getClientIp())
643-
* * Request::HEADER_CLIENT_HOST: defaults to X-Forwarded-Host (see getHost())
644-
* * Request::HEADER_CLIENT_PORT: defaults to X-Forwarded-Port (see getPort())
645-
* * Request::HEADER_CLIENT_PROTO: defaults to X-Forwarded-Proto (see getScheme() and isSecure())
646-
* * Request::HEADER_FORWARDED: defaults to Forwarded (see RFC 7239)
647-
*
648-
* Setting an empty value allows to disable the trusted header for the given key.
649-
*
650-
* @param string $key The header key
651-
* @param string $value The header name
652-
*
653-
* @throws \InvalidArgumentException
654-
*
655-
* @deprecated since version 3.3, to be removed in 4.0. Use "X-Forwarded-*" headers or the "Forwarded" header defined in RFC7239, and the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.
656-
*/
657-
public static function setTrustedHeaderName($key, $value)
658-
{
659-
@trigger_error(sprintf('The "%s()" method is deprecated since version 3.3 and will be removed in 4.0. Use "X-Forwarded-*" headers or the "Forwarded" header defined in RFC7239, and the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.', __METHOD__), E_USER_DEPRECATED);
660-
661-
if (!array_key_exists($key, self::$trustedHeaders)) {
662-
throw new \InvalidArgumentException(sprintf('Unable to set the trusted header name for key "%s".', $key));
663-
}
664-
665-
self::$trustedHeaders[$key] = $value;
666-
667-
if (null !== $value) {
668-
self::$trustedHeaderNames[$key] = $value;
669-
}
670-
}
671-
672-
/**
673-
* Gets the trusted proxy header name.
674-
*
675-
* @param string $key The header key
676-
*
677-
* @return string The header name
678-
*
679-
* @throws \InvalidArgumentException
680-
*
681-
* @deprecated since version 3.3, to be removed in 4.0. Use the Request::getTrustedHeaderSet() method instead.
682-
*/
683-
public static function getTrustedHeaderName($key)
684-
{
685-
if (2 > func_num_args() || func_get_arg(1)) {
686-
@trigger_error(sprintf('The "%s()" method is deprecated since version 3.3 and will be removed in 4.0. Use the Request::getTrustedHeaderSet() method instead.', __METHOD__), E_USER_DEPRECATED);
687-
}
688-
689-
if (!array_key_exists($key, self::$trustedHeaders)) {
690-
throw new \InvalidArgumentException(sprintf('Unable to get the trusted header name for key "%s".', $key));
691-
}
692-
693-
return self::$trustedHeaders[$key];
694-
}
695-
696607
/**
697608
* Normalizes a query string.
698609
*
@@ -860,7 +771,7 @@ public function getClientIps()
860771
return array($ip);
861772
}
862773

863-
return $this->getTrustedValues(self::HEADER_CLIENT_IP, $ip) ?: array($ip);
774+
return $this->getTrustedValues(self::HEADER_X_FORWARDED_FOR, $ip) ?: array($ip);
864775
}
865776

866777
/**
@@ -986,9 +897,9 @@ public function getScheme()
986897
*/
987898
public function getPort()
988899
{
989-
if ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_CLIENT_PORT)) {
900+
if ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_X_FORWARDED_PORT)) {
990901
$host = $host[0];
991-
} elseif ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_CLIENT_HOST)) {
902+
} elseif ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_X_FORWARDED_HOST)) {
992903
$host = $host[0];
993904
} elseif (!$host = $this->headers->get('HOST')) {
994905
return $this->server->get('SERVER_PORT');
@@ -1204,7 +1115,7 @@ public function getQueryString()
12041115
*/
12051116
public function isSecure()
12061117
{
1207-
if ($this->isFromTrustedProxy() && $proto = $this->getTrustedValues(self::HEADER_CLIENT_PROTO)) {
1118+
if ($this->isFromTrustedProxy() && $proto = $this->getTrustedValues(self::HEADER_X_FORWARDED_PROTO)) {
12081119
return in_array(strtolower($proto[0]), array('https', 'on', 'ssl', '1'), true);
12091120
}
12101121

@@ -1230,7 +1141,7 @@ public function isSecure()
12301141
*/
12311142
public function getHost()
12321143
{
1233-
if ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_CLIENT_HOST)) {
1144+
if ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_X_FORWARDED_HOST)) {
12341145
$host = $host[0];
12351146
} elseif (!$host = $this->headers->get('HOST')) {
12361147
if (!$host = $this->server->get('SERVER_NAME')) {
@@ -1520,11 +1431,8 @@ public function isMethod($method)
15201431
public function isMethodSafe(/* $andCacheable = true */)
15211432
{
15221433
if (!func_num_args() || func_get_arg(0)) {
1523-
// This deprecation should be turned into a BadMethodCallException in 4.0 (without adding the argument in the signature)
1524-
// then setting $andCacheable to false should be deprecated in 4.1
1525-
@trigger_error('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is deprecated since version 3.2 and will throw an exception in 4.0. Disable checking only for cacheable methods by calling the method with `false` as first argument or use the Request::isMethodCacheable() instead.', E_USER_DEPRECATED);
1526-
1527-
return in_array($this->getMethod(), array('GET', 'HEAD'));
1434+
// setting $andCacheable to false should be deprecated in 4.1
1435+
throw new \BadMethodCallException('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported.', E_USER_DEPRECATED);
15281436
}
15291437

15301438
return in_array($this->getMethod(), array('GET', 'HEAD', 'OPTIONS', 'TRACE'));
@@ -2016,7 +1924,7 @@ private function getTrustedValues($type, $ip = null)
20161924

20171925
if (self::$trustedHeaders[$type] && $this->headers->has(self::$trustedHeaders[$type])) {
20181926
foreach (explode(',', $this->headers->get(self::$trustedHeaders[$type])) as $v) {
2019-
$clientValues[] = (self::HEADER_CLIENT_PORT === $type ? '0.0.0.0:' : '').trim($v);
1927+
$clientValues[] = (self::HEADER_X_FORWARDED_PORT === $type ? '0.0.0.0:' : '').trim($v);
20201928
}
20211929
}
20221930

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.