[HttpFoundation] allowed any HTTP method for a Request
This commit is contained in:
parent
38d11aaf1a
commit
e8672740c7
@ -491,7 +491,7 @@ class Request
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = null;
|
||||
$this->server->set('REQUEST_METHOD', 'GET');
|
||||
$this->server->set('REQUEST_METHOD', $method);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -502,25 +502,9 @@ class Request
|
||||
public function getMethod()
|
||||
{
|
||||
if (null === $this->method) {
|
||||
switch ($this->server->get('REQUEST_METHOD', 'GET')) {
|
||||
case 'POST':
|
||||
$this->method = strtoupper($this->request->get('_method', 'POST'));
|
||||
break;
|
||||
|
||||
case 'PUT':
|
||||
$this->method = 'PUT';
|
||||
break;
|
||||
|
||||
case 'DELETE':
|
||||
$this->method = 'DELETE';
|
||||
break;
|
||||
|
||||
case 'HEAD':
|
||||
$this->method = 'HEAD';
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->method = 'GET';
|
||||
$this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
|
||||
if ('POST' === $this->method) {
|
||||
$this->method = strtoupper($this->request->get('_method', 'POST'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,11 +148,32 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
$request->initialize(null, null, null, null, null, array('SERVER_NAME' => 'www.exemple.com', 'HTTP_X_FORWARDED_HOST' => 'www.forward.com'));
|
||||
$this->assertEquals('www.forward.com', $request->getHost(), '->getHost() value from X_FORWARDED_HOST has priority over SERVER_NAME ');
|
||||
|
||||
|
||||
$request->initialize(null, null, null, null, null, array('SERVER_NAME' => 'www.exemple.com', 'HTTP_HOST' => 'www.host.com'));
|
||||
$this->assertEquals('www.host.com', $request->getHost(), '->getHost() value from Host header has priority over SERVER_NAME ');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\HttpFoundation\Request::setMethod
|
||||
* @covers Symfony\Component\HttpFoundation\Request::getMethod
|
||||
*/
|
||||
public function testGetSetMethod()
|
||||
{
|
||||
$request = new Request();
|
||||
|
||||
$this->assertEquals('GET', $request->getMethod(), '->getMethod() returns GET if no method is defined');
|
||||
|
||||
$request->setMethod('get');
|
||||
$this->assertEquals('GET', $request->getMethod(), '->getMethod() returns an uppercased string');
|
||||
|
||||
$request->setMethod('PURGE');
|
||||
$this->assertEquals('PURGE', $request->getMethod(), '->getMethod() returns the method even if it is not a standard one');
|
||||
|
||||
$request->setMethod('POST');
|
||||
$this->assertEquals('POST', $request->getMethod(), '->getMethod() returns the method POST if no _method is defined');
|
||||
|
||||
$request->setMethod('POST');
|
||||
$request->request->set('_method', 'purge');
|
||||
$this->assertEquals('PURGE', $request->getMethod(), '->getMethod() returns the method from _method if defined and POST');
|
||||
}
|
||||
|
||||
public function testInitializeConvertsUploadedFiles()
|
||||
|
Reference in New Issue
Block a user