Skip to content

Commit 48b95b6

Browse files
Merge branch '5.4' into 6.2
* 5.4: Do not check errored definitions’ type [HttpKernel] Fix restoring surrogate content from cache [HttpClient] Fix getting through proxies via CONNECT Remove legacy filters remnants
2 parents 32f8e20 + 514a0f9 commit 48b95b6

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

Response/AmpResponse.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ final class AmpResponse implements ResponseInterface, StreamableInterface
4747

4848
private AmpClientState $multi;
4949
private ?array $options;
50-
private CancellationTokenSource $canceller;
5150
private \Closure $onProgress;
5251

5352
private static ?string $delay = null;
@@ -73,7 +72,7 @@ public function __construct(AmpClientState $multi, Request $request, array $opti
7372

7473
$info = &$this->info;
7574
$headers = &$this->headers;
76-
$canceller = $this->canceller = new CancellationTokenSource();
75+
$canceller = new CancellationTokenSource();
7776
$handle = &$this->handle;
7877

7978
$info['url'] = (string) $request->getUri();

Response/CurlResponse.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,7 @@ public function __construct(CurlClientState $multi, \CurlHandle|string $ch, arra
7979
}
8080

8181
curl_setopt($ch, \CURLOPT_HEADERFUNCTION, static function ($ch, string $data) use (&$info, &$headers, $options, $multi, $id, &$location, $resolveRedirect, $logger): int {
82-
if (0 !== substr_compare($data, "\r\n", -2)) {
83-
return 0;
84-
}
85-
86-
$len = 0;
87-
88-
foreach (explode("\r\n", substr($data, 0, -2)) as $data) {
89-
$len += 2 + self::parseHeaderLine($ch, $data, $info, $headers, $options, $multi, $id, $location, $resolveRedirect, $logger);
90-
}
91-
92-
return $len;
82+
return self::parseHeaderLine($ch, $data, $info, $headers, $options, $multi, $id, $location, $resolveRedirect, $logger);
9383
});
9484

9585
if (null === $options) {
@@ -366,19 +356,29 @@ private static function select(ClientState $multi, float $timeout): int
366356
*/
367357
private static function parseHeaderLine($ch, string $data, array &$info, array &$headers, ?array $options, CurlClientState $multi, int $id, ?string &$location, ?callable $resolveRedirect, ?LoggerInterface $logger): int
368358
{
359+
if (!str_ends_with($data, "\r\n")) {
360+
return 0;
361+
}
362+
369363
$waitFor = @curl_getinfo($ch, \CURLINFO_PRIVATE) ?: '_0';
370364

371365
if ('H' !== $waitFor[0]) {
372366
return \strlen($data); // Ignore HTTP trailers
373367
}
374368

375-
if ('' !== $data) {
369+
$statusCode = curl_getinfo($ch, \CURLINFO_RESPONSE_CODE);
370+
371+
if ($statusCode !== $info['http_code'] && !preg_match("#^HTTP/\d+(?:\.\d+)? {$statusCode}(?: |\r\n$)#", $data)) {
372+
return \strlen($data); // Ignore headers from responses to CONNECT requests
373+
}
374+
375+
if ("\r\n" !== $data) {
376376
// Regular header line: add it to the list
377-
self::addResponseHeaders([$data], $info, $headers);
377+
self::addResponseHeaders([substr($data, 0, -2)], $info, $headers);
378378

379379
if (!str_starts_with($data, 'HTTP/')) {
380380
if (0 === stripos($data, 'Location:')) {
381-
$location = trim(substr($data, 9));
381+
$location = trim(substr($data, 9, -2));
382382
}
383383

384384
return \strlen($data);
@@ -401,7 +401,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
401401

402402
// End of headers: handle informational responses, redirects, etc.
403403

404-
if (200 > $statusCode = curl_getinfo($ch, \CURLINFO_RESPONSE_CODE)) {
404+
if (200 > $statusCode) {
405405
$multi->handlesActivity[$id][] = new InformationalChunk($statusCode, $headers);
406406
$location = null;
407407

0 commit comments

Comments
 (0)