Skip to content

Commit

Permalink
Add HEAD request support.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Feb 12, 2013
1 parent 32e60a2 commit 2430867
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/Cake/Network/Http/Client.php
Expand Up @@ -277,6 +277,20 @@ public function delete($url, $data = [], $options = []) {
return $this->_doRequest(Request::METHOD_DELETE, $url, $data, $options);
}

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

/**
* Helper method for doing non-GET requests.
*
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Network/Http/Message.php
Expand Up @@ -34,6 +34,7 @@ class Message {
const METHOD_PUT = 'PUT';
const METHOD_DELETE = 'DELETE';
const METHOD_PATCH = 'PATCH';
const METHOD_HEAD = 'HEAD';

/**
* The array of headers in the response.
Expand Down
28 changes: 28 additions & 0 deletions lib/Cake/Test/TestCase/Network/Http/ClientTest.php
Expand Up @@ -444,4 +444,32 @@ public function testCookieStorage() {
$http->get('/projects');
}

/**
* test head request with querystring data
*
* @return void
*/
public function testHeadQuerystring() {
$response = new Response();

$mock = $this->getMock('Cake\Network\Http\Adapter\Stream', ['send']);
$mock->expects($this->once())
->method('send')
->with($this->logicalAnd(
$this->isInstanceOf('Cake\Network\Http\Request'),
$this->attributeEqualTo('_method', Request::METHOD_HEAD),
$this->attributeEqualTo('_url', 'http://cakephp.org/search?q=hi+there')
))
->will($this->returnValue([$response]));

$http = new Client([
'host' => 'cakephp.org',
'adapter' => $mock
]);
$result = $http->head('/search', [
'q' => 'hi there',
]);
$this->assertSame($result, $response);
}

}

0 comments on commit 2430867

Please sign in to comment.