Permalink
Browse files

Ensuring request method is not improperly overwritten in `\action\Req…

…uest`.
  • Loading branch information...
1 parent 8306219 commit 5e0ad63f15b16141a55777b6763fc345e9b69f73 @nateabele nateabele committed Oct 1, 2012
Showing with 15 additions and 2 deletions.
  1. +3 −2 net/http/Request.php
  2. +12 −0 tests/cases/action/RequestTest.php
View
5 net/http/Request.php
@@ -36,7 +36,7 @@ class Request extends \lithium\net\http\Message {
*
* @var string
*/
- public $method = 'GET';
+ public $method;
/**
* Cookies.
@@ -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',
View
12 tests/cases/action/RequestTest.php
@@ -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.