Skip to content

Commit 3a3e2a6

Browse files
Merge branch '4.3' into 4.4
* 4.3: [OptionsResolve] Revert change in tests for a not-merged change in code [HttpClient] fix handling of 3xx with no Location header - ignore Content-Length when no body is expected [Workflow] Made the configuration more robust for the 'property' key [Security/Core] make NativePasswordEncoder use sodium to validate passwords when possible #30432 fix an error message fix paths to detect code owners [HttpClient] ignore the body of responses to HEAD requests [Validator] Ensure numeric subpaths do not cause errors on PHP 7.4 [SecurityBundle] Fix wrong assertion Remove unused local variables in tests [Yaml][Parser] Remove the getLastLineNumberBeforeDeprecation() internal unused method Make sure to collect child forms created on *_SET_DATA events [WebProfilerBundle] Improve display in Email panel for dark theme do not render errors for checkboxes twice
2 parents be5a53b + 4296c86 commit 3a3e2a6

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

CurlHttpClient.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ public function request(string $method, string $url, array $options = []): Respo
219219
if ('POST' === $method) {
220220
// Use CURLOPT_POST to have browser-like POST-to-GET redirects for 301, 302 and 303
221221
$curlopts[CURLOPT_POST] = true;
222+
} elseif ('HEAD' === $method) {
223+
$curlopts[CURLOPT_NOBODY] = true;
222224
} else {
223225
$curlopts[CURLOPT_CUSTOMREQUEST] = $method;
224226
}

Response/CurlResponse.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
356356

357357
if (200 > $statusCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE)) {
358358
$multi->handlesActivity[$id][] = new InformationalChunk($statusCode, $headers);
359+
$location = null;
359360

360361
return \strlen($data);
361362
}
@@ -379,9 +380,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
379380
}
380381
}
381382

382-
$location = null;
383-
384-
if ($statusCode < 300 || 400 <= $statusCode || curl_getinfo($ch, CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
383+
if ($statusCode < 300 || 400 <= $statusCode || null === $location || curl_getinfo($ch, CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
385384
// Headers and redirects completed, time to get the response's body
386385
$multi->handlesActivity[$id][] = new FirstChunk();
387386

@@ -405,6 +404,8 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
405404
$logger->info(sprintf('Redirecting: "%s %s"', $info['http_code'], $info['redirect_url']));
406405
}
407406

407+
$location = null;
408+
408409
return \strlen($data);
409410
}
410411
}

Response/MockResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ protected static function perform(ClientState $multi, array &$responses): void
183183
try {
184184
$offset = 0;
185185
$chunk[1]->getStatusCode();
186-
$response->headers = $chunk[1]->getHeaders(false);
186+
$chunk[1]->getHeaders(false);
187187
self::readResponse($response, $chunk[0], $chunk[1], $offset);
188188
$multi->handlesActivity[$id][] = new FirstChunk();
189189
$buffer = $response->requestOptions['buffer'] ?? null;
@@ -269,7 +269,7 @@ private static function readResponse(self $response, array $options, ResponseInt
269269
$info = $mock->getInfo() ?: [];
270270
$response->info['http_code'] = ($info['http_code'] ?? 0) ?: $mock->getStatusCode() ?: 200;
271271
$response->addResponseHeaders($info['response_headers'] ?? [], $response->info, $response->headers);
272-
$dlSize = isset($response->headers['content-encoding']) ? 0 : (int) ($response->headers['content-length'][0] ?? 0);
272+
$dlSize = isset($response->headers['content-encoding']) || 'HEAD' === $response->info['http_method'] || \in_array($response->info['http_code'], [204, 304], true) ? 0 : (int) ($response->headers['content-length'][0] ?? 0);
273273

274274
$response->info = [
275275
'start_time' => $response->info['start_time'],

Response/NativeResponse.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,16 @@ private function open(): void
195195
return;
196196
}
197197

198-
$this->multi->openHandles[$this->id] = [$h, $this->buffer, $this->inflate, $this->content, $this->onProgress, &$this->remaining, &$this->info];
199198
$this->multi->handlesActivity[$this->id] = [new FirstChunk()];
199+
200+
if ('HEAD' === $context['http']['method'] || \in_array($this->info['http_code'], [204, 304], true)) {
201+
$this->multi->handlesActivity[$this->id][] = null;
202+
$this->multi->handlesActivity[$this->id][] = null;
203+
204+
return;
205+
}
206+
207+
$this->multi->openHandles[$this->id] = [$h, $this->buffer, $this->inflate, $this->content, $this->onProgress, &$this->remaining, &$this->info];
200208
}
201209

202210
/**

0 commit comments

Comments
 (0)