From 450c3c4998d24bdc1912756114d3b42493b1ae99 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 24 Sep 2019 19:56:24 +0200 Subject: [PATCH] [HttpClient] fix race condition when reading response with informational status --- src/Symfony/Component/HttpClient/CurlHttpClient.php | 2 +- .../Component/HttpClient/Response/CurlResponse.php | 8 +++++--- .../Component/HttpClient/Response/NativeResponse.php | 6 +++++- .../Contracts/HttpClient/Test/Fixtures/web/index.php | 2 ++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/HttpClient/CurlHttpClient.php b/src/Symfony/Component/HttpClient/CurlHttpClient.php index a1d850f94d746..d2110d4132164 100644 --- a/src/Symfony/Component/HttpClient/CurlHttpClient.php +++ b/src/Symfony/Component/HttpClient/CurlHttpClient.php @@ -355,7 +355,7 @@ private static function handlePush($parent, $pushed, array $requestHeaders, Curl */ private static function acceptPushForRequest(string $method, array $options, PushedResponse $pushedResponse): bool { - if ($options['body'] || $method !== $pushedResponse->requestHeaders[':method'][0]) { + if ('' !== $options['body'] || $method !== $pushedResponse->requestHeaders[':method'][0]) { return false; } diff --git a/src/Symfony/Component/HttpClient/Response/CurlResponse.php b/src/Symfony/Component/HttpClient/Response/CurlResponse.php index 0b044630f62c7..532f4130860f3 100644 --- a/src/Symfony/Component/HttpClient/Response/CurlResponse.php +++ b/src/Symfony/Component/HttpClient/Response/CurlResponse.php @@ -121,15 +121,17 @@ public function __construct(CurlClientState $multi, $ch, array $options = null, if (\in_array($waitFor, ['headers', 'destruct'], true)) { try { - self::stream([$response])->current(); + foreach (self::stream([$response]) as $chunk) { + if ($chunk->isFirst()) { + break; + } + } } catch (\Throwable $e) { // Persist timeouts thrown during initialization $response->info['error'] = $e->getMessage(); $response->close(); throw $e; } - } elseif ('content' === $waitFor && ($response->multi->handlesActivity[$response->id][0] ?? null) instanceof FirstChunk) { - self::stream([$response])->current(); } curl_setopt($ch, CURLOPT_HEADERFUNCTION, null); diff --git a/src/Symfony/Component/HttpClient/Response/NativeResponse.php b/src/Symfony/Component/HttpClient/Response/NativeResponse.php index 7aa2d8022dc96..2f414e3ba2d17 100644 --- a/src/Symfony/Component/HttpClient/Response/NativeResponse.php +++ b/src/Symfony/Component/HttpClient/Response/NativeResponse.php @@ -65,7 +65,11 @@ public function __construct(NativeClientState $multi, $context, string $url, $op } if (null === $response->remaining) { - self::stream([$response])->current(); + foreach (self::stream([$response]) as $chunk) { + if ($chunk->isFirst()) { + break; + } + } } }; } diff --git a/src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php b/src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php index bc613868f2bf3..ec03bb61c2b84 100644 --- a/src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php +++ b/src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php @@ -45,6 +45,8 @@ header('HTTP/1.1 103 Early Hints'); header('Link: ; rel=preload; as=style', false); header('Link: ; rel=preload; as=script', false); + flush(); + usleep(1000); echo "HTTP/1.1 200 OK\r\n"; echo "Date: Fri, 26 May 2017 10:02:11 GMT\r\n"; echo "Content-Length: 13\r\n"; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy