2 Commits

Author SHA1 Message Date
Grischa Brockhaus
655607d739 parse_url does not return port as array, but it is used as array in Request.php
So I added a check, wether this is an array actually, else I use the port as intended as int. I would assume, that that array check is needless altogether but maybe old PHP versions needed that?
2021-06-02 13:41:15 +02:00
thenetexperts
14aa9aa691 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.
2017-02-24 09:06:01 -08:00
2 changed files with 14 additions and 1 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);
} }
@@ -552,7 +555,7 @@ class Request
$query = '?' . http_build_query(self::getArrayFromQuerystring($query)); $query = '?' . http_build_query(self::getArrayFromQuerystring($query));
} }
if ($port && $port[0] !== ':') { if ($port && (!is_array($port) || $port[0] !== ':')) {
$port = ':' . $port; $port = ':' . $port;
} }

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()
{ {