Skip to content

Commit

Permalink
feat(HEAD): CURLOPT_NOBODY option for HEAD requests
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
thenetexperts authored and Ahmad Nassri committed Feb 24, 2017
1 parent 842c0f2 commit 14aa9aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Unirest/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ public static function send($method, $url, $body = null, $headers = array(), $us
if ($method === Method::POST) {
curl_setopt(self::$handle, CURLOPT_POST, true);
} else {
if ($method === Method::HEAD) {
curl_setopt(self::$handle, CURLOPT_NOBODY, true);
}
curl_setopt(self::$handle, CURLOPT_CUSTOMREQUEST, $method);
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Unirest/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ public function testGetArray()
$this->assertEquals('John', $response->body->queryString->name[1]);
}

// HEAD
public function testHead()
{
$response = Request::head('http://mockbin.com/request?name=Mark', array(
'Accept' => 'application/json'
));

$this->assertEquals(200, $response->code);
}

// POST
public function testPost()
{
Expand Down

0 comments on commit 14aa9aa

Please sign in to comment.