From 89d1bcb6bab1f763674fb83a30a578643f4bd6c0 Mon Sep 17 00:00:00 2001 From: Denis Popov Date: Tue, 29 Dec 2020 00:22:16 +0300 Subject: [PATCH 1/2] fixed curl error "transfer closed with ... bytes remaining to read " with HEAD HTTP method Signed-off-by: Denis Popov --- src/Client/Adapter/Curl.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Client/Adapter/Curl.php b/src/Client/Adapter/Curl.php index c5a0c953..510590c9 100644 --- a/src/Client/Adapter/Curl.php +++ b/src/Client/Adapter/Curl.php @@ -387,6 +387,9 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = [], $body = curl_setopt($this->curl, CURLOPT_HTTP_VERSION, $curlHttp); curl_setopt($this->curl, $curlMethod, $curlValue); + // Set the CURLOPT_NOBODY flag for HEAD HTTP method + curl_setopt($this->curl,CURLOPT_NOBODY,$curlMethod === CURLOPT_CUSTOMREQUEST && $curlValue === 'HEAD'); + // Set the CURLINFO_HEADER_OUT flag so that we can retrieve the full request string later curl_setopt($this->curl, CURLINFO_HEADER_OUT, true); From 15e5a7846c3893279e6e537342d87d964a7c75dc Mon Sep 17 00:00:00 2001 From: Denis Popov Date: Tue, 29 Dec 2020 01:04:58 +0300 Subject: [PATCH 2/2] fix test HEAD request Signed-off-by: Denis Popov --- test/Client/CurlTest.php | 2 +- test/Client/_files/testHeadMethod.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/Client/_files/testHeadMethod.php diff --git a/test/Client/CurlTest.php b/test/Client/CurlTest.php index 22abe27b..d6e5205e 100644 --- a/test/Client/CurlTest.php +++ b/test/Client/CurlTest.php @@ -365,7 +365,7 @@ public function testGetCurlHandle() */ public function testHeadRequest() { - $this->client->setUri($this->baseuri . 'testRawPostData.php'); + $this->client->setUri($this->baseuri . 'testHeadMethod.php'); $adapter = new Adapter\Curl(); $this->client->setAdapter($adapter); $this->client->setMethod('HEAD'); diff --git a/test/Client/_files/testHeadMethod.php b/test/Client/_files/testHeadMethod.php new file mode 100644 index 00000000..a7a5155c --- /dev/null +++ b/test/Client/_files/testHeadMethod.php @@ -0,0 +1,12 @@ +