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.
This commit is contained in:
thenetexperts
2017-02-24 18:06:01 +01:00
committed by Ahmad Nassri
parent 842c0f242d
commit 14aa9aa691
2 changed files with 13 additions and 0 deletions

View File

@@ -399,6 +399,9 @@ class Request
if ($method === Method::POST) { if ($method === Method::POST) {
curl_setopt(self::$handle, CURLOPT_POST, true); curl_setopt(self::$handle, CURLOPT_POST, true);
} else { } else {
if ($method === Method::HEAD) {
curl_setopt(self::$handle, CURLOPT_NOBODY, true);
}
curl_setopt(self::$handle, CURLOPT_CUSTOMREQUEST, $method); curl_setopt(self::$handle, CURLOPT_CUSTOMREQUEST, $method);
} }

View File

@@ -251,6 +251,16 @@ class UnirestRequestTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('John', $response->body->queryString->name[1]); $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 // POST
public function testPost() public function testPost()
{ {