[HTTP Foundation] Deprecate passing argument to method Request::isMethodSafe()

This commit is contained in:
dFayet 2019-05-28 18:10:09 +02:00 committed by Fabien Potencier
parent ec9159e074
commit 59fa1bd127
8 changed files with 14 additions and 22 deletions

View File

@ -204,7 +204,7 @@ class BinaryFileResponse extends Response
if (!$this->headers->has('Accept-Ranges')) {
// Only accept ranges on safe HTTP methods
$this->headers->set('Accept-Ranges', $request->isMethodSafe(false) ? 'bytes' : 'none');
$this->headers->set('Accept-Ranges', $request->isMethodSafe() ? 'bytes' : 'none');
}
if (self::$trustXSendfileTypeHeader && $request->headers->has('X-Sendfile-Type')) {

View File

@ -1,6 +1,11 @@
CHANGELOG
=========
4.4.0
-----
* passing arguments to `Request::isMethodSafe()` is deprecated.
4.3.0
-----

View File

@ -1437,15 +1437,12 @@ class Request
*
* @see https://tools.ietf.org/html/rfc7231#section-4.2.1
*
* @param bool $andCacheable Adds the additional condition that the method should be cacheable. True by default.
*
* @return bool
*/
public function isMethodSafe(/* $andCacheable = true */)
public function isMethodSafe()
{
if (!\func_num_args() || func_get_arg(0)) {
// setting $andCacheable to false should be deprecated in 4.1
throw new \BadMethodCallException('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported.');
if (\func_num_args() > 0) {
@trigger_error(sprintf('Passing arguments to "%s()" has been deprecated since Symfony 4.4; use "%s::isMethodCacheable() to check if the method is cacheable instead."', __METHOD__, __CLASS__), E_USER_DEPRECATED);
}
return \in_array($this->getMethod(), ['GET', 'HEAD', 'OPTIONS', 'TRACE']);

View File

@ -2115,7 +2115,7 @@ class RequestTest extends TestCase
{
$request = new Request();
$request->setMethod($method);
$this->assertEquals($safe, $request->isMethodSafe(false));
$this->assertEquals($safe, $request->isMethodSafe());
}
public function methodSafeProvider()
@ -2134,16 +2134,6 @@ class RequestTest extends TestCase
];
}
/**
* @expectedException \BadMethodCallException
*/
public function testMethodSafeChecksCacheable()
{
$request = new Request();
$request->setMethod('OPTIONS');
$request->isMethodSafe();
}
/**
* @dataProvider methodCacheableProvider
*/

View File

@ -79,7 +79,7 @@ class FragmentListener implements EventSubscriberInterface
protected function validateRequest(Request $request)
{
// is the Request safe?
if (!$request->isMethodSafe(false)) {
if (!$request->isMethodSafe()) {
throw new AccessDeniedHttpException();
}

View File

@ -207,7 +207,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
$this->traces[$this->getTraceKey($request)] = [];
if (!$request->isMethodSafe(false)) {
if (!$request->isMethodSafe()) {
$response = $this->invalidate($request, $catch);
} elseif ($request->headers->has('expect') || !$request->isMethodCacheable()) {
$response = $this->pass($request, $catch);

View File

@ -18,7 +18,7 @@
"require": {
"php": "^7.1.3",
"symfony/event-dispatcher": "^4.3",
"symfony/http-foundation": "^4.1.1|^5.0",
"symfony/http-foundation": "^4.4|^5.0",
"symfony/debug": "^3.4|^4.0|^5.0",
"symfony/polyfill-ctype": "^1.8",
"symfony/polyfill-php73": "^1.9",

View File

@ -208,7 +208,7 @@ class ExceptionListener
protected function setTargetPath(Request $request)
{
// session isn't required when using HTTP basic authentication mechanism for example
if ($request->hasSession() && $request->isMethodSafe(false) && !$request->isXmlHttpRequest()) {
if ($request->hasSession() && $request->isMethodSafe() && !$request->isXmlHttpRequest()) {
$this->saveTargetPath($request->getSession(), $this->providerKey, $request->getUri());
}
}