[HttpFoundation] Add OPTIONS and TRACE to the list of safe methods

This commit is contained in:
Kévin Dunglas 2016-07-09 10:59:31 +02:00 committed by Fabien Potencier
parent b7ed32a36b
commit 1404607072
2 changed files with 27 additions and 1 deletions

View File

@ -1470,7 +1470,7 @@ class Request
*/
public function isMethodSafe()
{
return in_array($this->getMethod(), array('GET', 'HEAD'));
return in_array($this->getMethod(), array('GET', 'HEAD', 'OPTIONS', 'TRACE'));
}
/**

View File

@ -1912,6 +1912,32 @@ class RequestTest extends \PHPUnit_Framework_TestCase
array(str_repeat(':', 101)),
);
}
/**
* @dataProvider methodSafeProvider
*/
public function testMethodSafe($method, $safe)
{
$request = new Request();
$request->setMethod($method);
$this->assertEquals($safe, $request->isMethodSafe());
}
public function methodSafeProvider()
{
return array(
array('HEAD', true),
array('GET', true),
array('POST', false),
array('PUT', false),
array('PATCH', false),
array('DELETE', false),
array('PURGE', false),
array('OPTIONS', true),
array('TRACE', true),
array('CONNECT', false),
);
}
}
class RequestContentProxy extends Request