Skip to content

Commit 121bebf

Browse files
committed
fix HTTP HEAD requests when using 'Connection: Keep-Alive'
1 parent 4fa33f5 commit 121bebf

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/ArangoDBClient/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ private function executeRequest($method, $url, $data, array $customHeaders = [])
458458
$startTime = microtime(true);
459459
}
460460

461-
$result = HttpHelper::transfer($handle, $request);
461+
$result = HttpHelper::transfer($handle, $request, $method);
462462

463463
if ($traceFunc) {
464464
// only issue syscall if we need it

lib/ArangoDBClient/HttpHelper.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,12 @@ public static function validateMethod($method)
207207
*
208208
* @param resource $socket - connection socket (must be open)
209209
* @param string $request - complete HTTP request as a string
210+
* @param string $method - HTTP method used (e.g. "HEAD")
210211
*
211212
* @throws ClientException
212213
* @return string - HTTP response string as provided by the server
213214
*/
214-
public static function transfer($socket, $request)
215+
public static function transfer($socket, $request, $method)
215216
{
216217
if (!is_resource($socket)) {
217218
throw new ClientException('Invalid socket used');
@@ -255,6 +256,13 @@ public static function transfer($socket, $request)
255256
if ($pos !== false) {
256257
$contentLength = (int) substr($result, $pos + 16, 10); // 16 = strlen("content-length: ")
257258
$contentLengthPos = $pos + 17; // 17 = 16 + 1 one digit
259+
260+
if ($method === "HEAD") {
261+
// for HTTP HEAD requests, the server will respond
262+
// with the proper Content-Length value, but will
263+
// NOT return the body.
264+
$contentLength = 0;
265+
}
258266
}
259267
}
260268

0 commit comments

Comments
 (0)