Skip to content

Commit

Permalink
Merge pull request #6370 from egeloen/network-http
Browse files Browse the repository at this point in the history
[Network][Http] Migration from 2.x to 3.x
  • Loading branch information
lorenzo committed Apr 20, 2015
2 parents 6fb4f26 + ad8b0cc commit 6628a30
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Network/Http/Adapter/Stream.php
Expand Up @@ -66,6 +66,7 @@ public function send(Request $request, array $options)
{
$this->_stream = null;
$this->_context = [];
$this->_contextOptions = [];
$this->_connectionErrors = [];

$this->_buildContext($request, $options);
Expand Down
30 changes: 30 additions & 0 deletions src/Network/Http/Client.php
Expand Up @@ -254,6 +254,36 @@ public function patch($url, $data = [], array $options = [])
return $this->_doRequest(Request::METHOD_PATCH, $url, $data, $options);
}

/**
* Do an OPTIONS request.
*
* @param string $url The url or path you want to request.
* @param mixed $data The request data you want to send.
* @param array $options Additional options for the request.
* @return \Cake\Network\Http\Response
*/
public function options($url, $data = [], array $options = [])
{
$options = $this->_mergeOptions($options);
$url = $this->buildUrl($url, [], $options);
return $this->_doRequest(Request::METHOD_OPTIONS, $url, $data, $options);
}

/**
* Do a TRACE request.
*
* @param string $url The url or path you want to request.
* @param mixed $data The request data you want to send.
* @param array $options Additional options for the request.
* @return \Cake\Network\Http\Response
*/
public function trace($url, $data = [], array $options = [])
{
$options = $this->_mergeOptions($options);
$url = $this->buildUrl($url, [], $options);
return $this->_doRequest(Request::METHOD_TRACE, $url, $data, $options);
}

/**
* Do a DELETE request.
*
Expand Down
14 changes: 14 additions & 0 deletions src/Network/Http/Message.php
Expand Up @@ -106,6 +106,20 @@ class Message
*/
const METHOD_PATCH = 'PATCH';

/**
* HTTP OPTIONS method
*
* @var string
*/
const METHOD_OPTIONS = 'OPTIONS';

/**
* HTTP TRACE method
*
* @var string
*/
const METHOD_TRACE = 'TRACE';

/**
* HTTP HEAD method
*
Expand Down
17 changes: 17 additions & 0 deletions src/Network/Http/Request.php
Expand Up @@ -173,4 +173,21 @@ public function cookie($name, $value = null)
}
return $this;
}

/**
* Get/Set http version.
*
* @param string|null $version The http version.
*
* @return $this|string Either $this or the http version.
*/
public function version($version = null)
{
if ($version === null) {
return parent::version();
}

$this->_version = $version;
return $this;
}
}
2 changes: 2 additions & 0 deletions tests/TestCase/Network/Http/ClientTest.php
Expand Up @@ -319,6 +319,8 @@ public static function methodProvider()
[Request::METHOD_PUT],
[Request::METHOD_DELETE],
[Request::METHOD_PATCH],
[Request::METHOD_OPTIONS],
[Request::METHOD_TRACE],
];
}
/**
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Network/Http/RequestTest.php
Expand Up @@ -119,4 +119,18 @@ public function testCookie()
$result = $request->cookie('session');
$this->assertEquals('123456', $result);
}

/**
* test version method.
*
* @return void
*/
public function testVersion()
{
$request = new Request();
$result = $request->version('1.0');
$this->assertSame($request, $request, 'Should return self');

$this->assertSame('1.0', $request->version());
}
}

0 comments on commit 6628a30

Please sign in to comment.