Skip to content

Commit 5309e5e

Browse files
[HttpClient] ignore the body of responses to HEAD requests
1 parent 3c37c0b commit 5309e5e

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CurlHttpClient.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ public function request(string $method, string $url, array $options = []): Respo
197197
if ('POST' === $method) {
198198
// Use CURLOPT_POST to have browser-like POST-to-GET redirects for 301, 302 and 303
199199
$curlopts[CURLOPT_POST] = true;
200+
} elseif ('HEAD' === $method) {
201+
$curlopts[CURLOPT_NOBODY] = true;
200202
} else {
201203
$curlopts[CURLOPT_CUSTOMREQUEST] = $method;
202204
}

Response/MockResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ protected static function perform(ClientState $multi, array &$responses): void
176176
try {
177177
$offset = 0;
178178
$chunk[1]->getStatusCode();
179-
$response->headers = $chunk[1]->getHeaders(false);
179+
$chunk[1]->getHeaders(false);
180180
self::readResponse($response, $chunk[0], $chunk[1], $offset);
181181
$multi->handlesActivity[$id][] = new FirstChunk();
182182
} catch (\Throwable $e) {

Response/NativeResponse.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,16 @@ private function open(): void
174174
$this->inflate = null;
175175
}
176176

177-
$this->multi->openHandles[$this->id] = [$h, $this->buffer, $this->inflate, $this->content, $this->onProgress, &$this->remaining, &$this->info];
178177
$this->multi->handlesActivity[$this->id] = [new FirstChunk()];
178+
179+
if ('HEAD' === $context['http']['method']) {
180+
$this->multi->handlesActivity[$this->id][] = null;
181+
$this->multi->handlesActivity[$this->id][] = null;
182+
183+
return;
184+
}
185+
186+
$this->multi->openHandles[$this->id] = [$h, $this->buffer, $this->inflate, $this->content, $this->onProgress, &$this->remaining, &$this->info];
179187
}
180188

181189
/**

0 commit comments

Comments
 (0)