Skip to content

Commit

Permalink
Ensuring request method is not improperly overwritten in `\action\Req…
Browse files Browse the repository at this point in the history
…uest`.
  • Loading branch information
nateabele committed Oct 1, 2012
1 parent 8306219 commit 5e0ad63
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions net/http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Request extends \lithium\net\http\Message {
*
* @var string
*/
public $method = 'GET';
public $method;

/**
* Cookies.
Expand Down Expand Up @@ -84,7 +84,8 @@ public function __construct(array $config = array()) {
'followLocation' => true
);
parent::__construct($config + $defaults);
$this->method = $this->_config['method'];
$this->method = $this->method ?: $this->_config['method'];

$this->headers = array(
'Host' => $this->port ? "{$this->host}:{$this->port}" : $this->host,
'Connection' => 'Close',
Expand Down
12 changes: 12 additions & 0 deletions tests/cases/action/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,18 @@ public function testConvertToUrl2() {
$expected = 'https://foo.com/the/base/path/posts?some=query&parameter=values';
$this->assertEqual($expected, $request->to('url'));
}

/**
* Tests that the HTTP request method set by `Request` from the server information is not
* overwritten in a parent class.
*/
public function testRequesMethodConfiguration() {
$request = new Request(array('env' => array('REQUEST_METHOD' => 'POST')));
$this->assertEqual('POST', $request->method);

$request = new Request(array('env' => array('REQUEST_METHOD' => 'PATCH')));
$this->assertEqual('PATCH', $request->method);
}
}

?>

0 comments on commit 5e0ad63

Please sign in to comment.