8000 feature #22863 [HttpFoundation] remove deprecated features (xabbuh) · symfony/symfony@0a084dd · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a084dd

Browse files
committed
feature #22863 [HttpFoundation] remove deprecated features (xabbuh)
This PR was merged into the 4.0-dev branch. Discussion ---------- [HttpFoundation] remove deprecated features | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 17c7a2d [HttpFoundation] remove deprecated features
2 parents e37de30 + 17c7a2d commit 0a084dd

File tree

4 files changed

+48
-261
lines changed

4 files changed

+48
-261
lines changed

src/Symfony/Component/HttpFoundation/CHANGELOG.md

Lines 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

Lines changed: 26 additions & 122 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,20 +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-
@trigger_error(sprintf('The %s() method expects a bit field of Request::HEADER_* as second argument since version 3.3. Defining it will be required in 4.0. ', __METHOD__), E_USER_DEPRECATED);
581-
582-
return;
583-
}
584-
$trustedHeaderSet = (int) func_get_arg(1);
585-
586-
foreach (self::$trustedHeaderNames as $header => $name) {
587-
self::$trustedHeaders[$header] = $header & $trustedHeaderSet ? $name : null;
588-
}
589558
self::$trustedHeaderSet = $trustedHeaderSet;
590559
}
591560

@@ -635,68 +604,6 @@ public static function getTrustedHosts()
635604
return self::$trustedHostPatterns;
636605
}
637606

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

867-
return $this->getTrustedValues(self::HEADER_CLIENT_IP, $ip) ?: array($ip);
774+
return $this->getTrustedValues(self::HEADER_X_FORWARDED_FOR, $ip) ?: array($ip);
868775
}
869776

870777
/**
@@ -991,9 +898,9 @@ public function getScheme()
991898
*/
992899
public function getPort()
993900
{
994-
if ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_CLIENT_PORT)) {
901+
if ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_X_FORWARDED_PORT)) {
995902
$host = $host[0];
996-
} elseif ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_CLIENT_HOST)) {
903+
} elseif ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_X_FORWARDED_HOST)) {
997904
$host = $host[0];
998905
} elseif (!$host = $this->headers->get('HOST')) {
999906
return $this->server->get('SERVER_PORT');
@@ -1209,7 +1116,7 @@ public function getQueryString()
12091116
*/
12101117
public function isSecure()
12111118
{
1212-
if ($this->isFromTrustedProxy() && $proto = $this->getTrustedValues(self::HEADER_CLIENT_PROTO)) {
1119+
if ($this->isFromTrustedProxy() && $proto = $this->getTrustedValues(self::HEADER_X_FORWARDED_PROTO)) {
12131120
return in_array(strtolower($proto[0]), array('https', 'on', 'ssl', '1'), true);
12141121
}
12151122

@@ -1236,7 +1143,7 @@ public function isSecure()
12361143
*/
12371144
public function getHost()
12381145
{
1239-
if ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_CLIENT_HOST)) {
1146+
if ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_X_FORWARDED_HOST)) {
12401147
$host = $host[0];
12411148
} elseif (!$host = $this->headers->get('HOST')) {
12421149
if (!$host = $this->server->get('SERVER_NAME')) {
@@ -1526,11 +1433,8 @@ public function isMethod($method)
15261433
public function isMethodSafe(/* $andCacheable = true */)
15271434
{
15281435
if (!func_num_args() || func_get_arg(0)) {
1529-
// This deprecation should be turned into a BadMethodCallException in 4.0 (without adding the argument in the signature)
1530-
// then setting $andCacheable to false should be deprecated in 4.1
1531-
@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);
1532-
1533-
return in_array($this->getMethod(), array('GET', 'HEAD'));
1436+
// setting $andCacheable to false should be deprecated in 4.1
1437+
throw new \BadMethodCallException('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported.', E_USER_DEPRECATED);
15341438
}
15351439

15361440
return in_array($this->getMethod(), array('GET', 'HEAD', 'OPTIONS', 'TRACE'));
@@ -2022,7 +1926,7 @@ private function getTrustedValues($type, $ip = null)
20221926

20231927
if (self::$trustedHeaders[$type] && $this->headers->has(self::$trustedHeaders[$type])) {
20241928
foreach (explode(',', $this->headers->get(self::$trustedHeaders[$type])) as $v) {
2025-
$clientValues[] = (self::HEADER_CLIENT_PORT === $type ? '0.0.0.0:' : '').trim($v);
1929+
$clientValues[] = (self::HEADER_X_FORWARDED_PORT === $type ? '0.0.0.0:' : '').trim($v);
20261930
}
20271931
}
20281932

0 commit comments

Comments
 (0)
0