Skip to content

Commit

Permalink
[HttpFoundation] allowed any HTTP method for a Request
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Dec 8, 2010
1 parent 38d11aa commit e867274
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
24 changes: 4 additions & 20 deletions src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -491,7 +491,7 @@ public function getHost()
public function setMethod($method)
{
$this->method = null;
$this->server->set('REQUEST_METHOD', 'GET');
$this->server->set('REQUEST_METHOD', $method);
}

/**
Expand All @@ -502,25 +502,9 @@ public function setMethod($method)
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'));
}
}

Expand Down
23 changes: 22 additions & 1 deletion tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php
Expand Up @@ -148,11 +148,32 @@ public function testGetHost()
$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()
Expand Down

0 comments on commit e867274

Please sign in to comment.