Skip to content

Commit

Permalink
Merge pull request #5253 from cakephp/issue-5234
Browse files Browse the repository at this point in the history
Make the version option function as intended.
  • Loading branch information
lorenzo committed Nov 25, 2014
2 parents 1fed92d + 1e6d22b commit 5a9bef2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/Cake/Network/Http/HttpSocket.php
Expand Up @@ -877,11 +877,10 @@ protected function _parseQuery($query) {
* Builds a request line according to HTTP/1.1 specs. Activate quirks mode to work outside specs.
*
* @param array $request Needs to contain a 'uri' key. Should also contain a 'method' key, otherwise defaults to GET.
* @param string $versionToken The version token to use, defaults to HTTP/1.1
* @return string Request line
* @throws SocketException
*/
protected function _buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
protected function _buildRequestLine($request = array()) {
$asteriskMethods = array('OPTIONS');

if (is_string($request)) {
Expand All @@ -907,7 +906,8 @@ protected function _buildRequestLine($request = array(), $versionToken = 'HTTP/1
if (!$this->quirksMode && $request['uri'] === '*' && !in_array($request['method'], $asteriskMethods)) {
throw new SocketException(__d('cake_dev', 'HttpSocket::_buildRequestLine - The "*" asterisk character is only allowed for the following methods: %s. Activate quirks mode to work outside of HTTP/1.1 specs.', implode(',', $asteriskMethods)));
}
return $request['method'] . ' ' . $request['uri'] . ' ' . $versionToken . "\r\n";
$version = isset($request['version']) ? $request['version'] : '1.1';
return $request['method'] . ' ' . $request['uri'] . ' HTTP/' . $version . "\r\n";
}

/**
Expand Down
21 changes: 16 additions & 5 deletions lib/Cake/Test/Case/Network/Http/HttpSocketTest.php
Expand Up @@ -138,8 +138,8 @@ public function parseQuery($query) {
* @param string $versionToken The version token to use, defaults to HTTP/1.1
* @return string Request line
*/
public function buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
return parent::_buildRequestLine($request, $versionToken);
public function buildRequestLine($request = array()) {
return parent::_buildRequestLine($request);
}

/**
Expand Down Expand Up @@ -525,13 +525,16 @@ public function testRequest() {
),
array(
'request' => array(
'version' => '1.0',
'method' => 'POST',
'uri' => 'https://www.cakephp.org/posts/add',
'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'),
'cookies' => array('foo' => array('value' => 'bar'))
),
'expectation' => array(
'request' => array(
'version' => '1.0',
'line' => "POST /posts/add HTTP/1.0\r\n",
'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\nCookie: foo=bar\r\n",
'cookies' => array(
'foo' => array('value' => 'bar'),
Expand Down Expand Up @@ -1245,9 +1248,6 @@ public function testBuildRequestLine() {
$r = $this->Socket->buildRequestLine($request);
$this->assertEquals("GET /search?q=socket HTTP/1.1\r\n", $r);

$r = $this->Socket->buildRequestLine($request, 'CAKE-HTTP/0.1');
$this->assertEquals("GET /search?q=socket CAKE-HTTP/0.1\r\n", $r);

$request = array('method' => 'OPTIONS', 'uri' => '*');
$r = $this->Socket->buildRequestLine($request);
$this->assertEquals("OPTIONS * HTTP/1.1\r\n", $r);
Expand All @@ -1259,6 +1259,17 @@ public function testBuildRequestLine() {

$r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n");
$this->assertEquals("GET * HTTP/1.1\r\n", $r);

$request = array(
'version' => '1.0',
'method' => 'GET',
'uri' => array(
'path' => '/search',
'query' => array('q' => 'socket')
)
);
$r = $this->Socket->buildRequestLine($request);
$this->assertEquals("GET /search?q=socket HTTP/1.0\r\n", $r);
}

/**
Expand Down

0 comments on commit 5a9bef2

Please sign in to comment.