feature #19322 [HttpFoundation] Add Request::isMethodIdempotent method (dunglas)
This PR was squashed before being merged into the 3.2-dev branch (closes #19322).
Discussion
----------
[HttpFoundation] Add Request::isMethodIdempotent method
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
Addd a new method in the spirit of `isMethodSafe` to know if the current method is idempotent according to RFCs.
Commits
-------
44df6a4
[HttpFoundation] Add Request::isMethodIdempotent method
This commit is contained in:
commit
0fc2b622e8
@ -1473,7 +1473,7 @@ class Request
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the method is safe or not.
|
||||
* Checks whether or not the method is safe.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@ -1482,6 +1482,16 @@ class Request
|
||||
return in_array($this->getMethod(), array('GET', 'HEAD'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the method is idempotent.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMethodIdempotent()
|
||||
{
|
||||
return in_array($this->getMethod(), array('HEAD', 'GET', 'PUT', 'DELETE', 'TRACE', 'OPTIONS', 'PURGE'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request body content.
|
||||
*
|
||||
|
@ -1951,6 +1951,32 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
array(str_repeat(':', 101)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider methodIdempotentProvider
|
||||
*/
|
||||
public function testMethodIdempotent($method, $idempotent)
|
||||
{
|
||||
$request = new Request();
|
||||
$request->setMethod($method);
|
||||
$this->assertEquals($idempotent, $request->isMethodIdempotent());
|
||||
}
|
||||
|
||||
public function methodIdempotentProvider()
|
||||
{
|
||||
return array(
|
||||
array('HEAD', true),
|
||||
array('GET', true),
|
||||
array('POST', false),
|
||||
array('PUT', true),
|
||||
array('PATCH', false),
|
||||
array('DELETE', true),
|
||||
array('PURGE', true),
|
||||
array('OPTIONS', true),
|
||||
array('TRACE', true),
|
||||
array('CONNECT', false),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RequestContentProxy extends Request
|
||||
|
Reference in New Issue
Block a user