Skip to content

Commit 14aa9aa

Browse files
thenetexpertsahmadnassri
authored andcommitted
feat(HEAD): CURLOPT_NOBODY option for HEAD requests
* When using HEAD requests set the appropriate curl header to not wait for a response body. See http://www.php.net/manual/en/function.curl-setopt.php on CURLOPT_NOBODY. * Add simple test for HEAD request.
1 parent 842c0f2 commit 14aa9aa

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Unirest/Request.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ public static function send($method, $url, $body = null, $headers = array(), $us
399399
if ($method === Method::POST) {
400400
curl_setopt(self::$handle, CURLOPT_POST, true);
401401
} else {
402+
if ($method === Method::HEAD) {
403+
curl_setopt(self::$handle, CURLOPT_NOBODY, true);
404+
}
402405
curl_setopt(self::$handle, CURLOPT_CUSTOMREQUEST, $method);
403406
}
404407

tests/Unirest/RequestTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ public function testGetArray()
251251
$this->assertEquals('John', $response->body->queryString->name[1]);
252252
}
253253

254+
// HEAD
255+
public function testHead()
256+
{
257+
$response = Request::head('http://mockbin.com/request?name=Mark', array(
258+
'Accept' => 'application/json'
259+
));
260+
261+
$this->assertEquals(200, $response->code);
262+
}
263+
254264
// POST
255265
public function testPost()
256266
{

0 commit comments

Comments
 (0)