From 792b970c51518609cb01adfe117ab10f83660a43 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 20 Nov 2024 16:26:44 +0100 Subject: [PATCH] [HttpClient] Fix computing stats for PUSH with Amp --- .../HttpClient/Response/AmpResponseV4.php | 11 ++++ .../HttpClient/Response/AmpResponseV5.php | 11 ++++ .../HttpClient/Tests/HttpClientTestCase.php | 54 +++++++++---------- .../Tests/RetryableHttpClientTest.php | 2 +- .../Component/HttpClient/Tests/TestLogger.php | 2 +- 5 files changed, 51 insertions(+), 29 deletions(-) diff --git a/src/Symfony/Component/HttpClient/Response/AmpResponseV4.php b/src/Symfony/Component/HttpClient/Response/AmpResponseV4.php index 63147f0703aa0..c67c818c19cf3 100644 --- a/src/Symfony/Component/HttpClient/Response/AmpResponseV4.php +++ b/src/Symfony/Component/HttpClient/Response/AmpResponseV4.php @@ -433,6 +433,17 @@ private static function getPushedResponse(Request $request, AmpClientStateV4 $mu } } + $info += [ + 'connect_time' => 0.0, + 'pretransfer_time' => 0.0, + 'starttransfer_time' => 0.0, + 'total_time' => 0.0, + 'namelookup_time' => 0.0, + 'primary_ip' => '', + 'primary_port' => 0, + 'start_time' => microtime(true), + ]; + $pushDeferred->resolve(); $logger?->debug(\sprintf('Accepting pushed response: "%s %s"', $info['http_method'], $info['url'])); self::addResponseHeaders($response, $info, $headers); diff --git a/src/Symfony/Component/HttpClient/Response/AmpResponseV5.php b/src/Symfony/Component/HttpClient/Response/AmpResponseV5.php index 4074f6da531a5..da8b3ba82ada9 100644 --- a/src/Symfony/Component/HttpClient/Response/AmpResponseV5.php +++ b/src/Symfony/Component/HttpClient/Response/AmpResponseV5.php @@ -434,6 +434,17 @@ private static function getPushedResponse(Request $request, AmpClientStateV5 $mu } } + $info += [ + 'connect_time' => 0.0, + 'pretransfer_time' => 0.0, + 'starttransfer_time' => 0.0, + 'total_time' => 0.0, + 'namelookup_time' => 0.0, + 'primary_ip' => '', + 'primary_port' => 0, + 'start_time' => microtime(true), + ]; + $pushDeferred->complete(); $logger?->debug(\sprintf('Accepting pushed response: "%s %s"', $info['http_method'], $info['url'])); self::addResponseHeaders($response, $info, $headers); diff --git a/src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php b/src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php index ee1b1d58448a0..db80869579973 100644 --- a/src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php +++ b/src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php @@ -200,20 +200,20 @@ public function testHttp2PushVulcain() $client->reset(); - $expected = [ - 'Request: "GET https://127.0.0.1:3000/json"', - 'Queueing pushed response: "https://127.0.0.1:3000/json/1"', - 'Queueing pushed response: "https://127.0.0.1:3000/json/2"', - 'Queueing pushed response: "https://127.0.0.1:3000/json/3"', - 'Response: "200 https://127.0.0.1:3000/json"', - 'Accepting pushed response: "GET https://127.0.0.1:3000/json/1"', - 'Response: "200 https://127.0.0.1:3000/json/1"', - 'Accepting pushed response: "GET https://127.0.0.1:3000/json/2"', - 'Response: "200 https://127.0.0.1:3000/json/2"', - 'Accepting pushed response: "GET https://127.0.0.1:3000/json/3"', - 'Response: "200 https://127.0.0.1:3000/json/3"', - ]; - $this->assertSame($expected, $logger->logs); + $expected = <<assertStringMatchesFormat($expected, implode("\n", $logger->logs)); } public function testPause() @@ -288,19 +288,19 @@ public function testHttp2PushVulcainWithUnusedResponse() $client->reset(); - $expected = [ - 'Request: "GET https://127.0.0.1:3000/json"', - 'Queueing pushed response: "https://127.0.0.1:3000/json/1"', - 'Queueing pushed response: "https://127.0.0.1:3000/json/2"', - 'Queueing pushed response: "https://127.0.0.1:3000/json/3"', - 'Response: "200 https://127.0.0.1:3000/json"', - 'Accepting pushed response: "GET https://127.0.0.1:3000/json/1"', - 'Response: "200 https://127.0.0.1:3000/json/1"', - 'Accepting pushed response: "GET https://127.0.0.1:3000/json/2"', - 'Response: "200 https://127.0.0.1:3000/json/2"', - 'Unused pushed response: "https://127.0.0.1:3000/json/3"', - ]; - $this->assertSame($expected, $logger->logs); + $expected = <<assertStringMatchesFormat($expected, implode("\n", $logger->logs)); } public function testDnsFailure() diff --git a/src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php b/src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php index 4162a6c4a70f4..1a79ef522c4c8 100644 --- a/src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php +++ b/src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php @@ -176,7 +176,7 @@ public function shouldRetry(AsyncContext $context, ?string $responseContent, ?Tr $this->assertSame('Could not resolve host "does.not.exists".', $e->getMessage()); } $this->assertCount(2, $logger->logs); - $this->assertSame('Try #{count} after {delay}ms: Could not resolve host "does.not.exists".', $logger->logs[0]); + $this->assertSame('Try #1 after 0ms: Could not resolve host "does.not.exists".', $logger->logs[0]); } public function testCancelOnTimeout() diff --git a/src/Symfony/Component/HttpClient/Tests/TestLogger.php b/src/Symfony/Component/HttpClient/Tests/TestLogger.php index 0e241e40a6e97..b9c7aba5f8895 100644 --- a/src/Symfony/Component/HttpClient/Tests/TestLogger.php +++ b/src/Symfony/Component/HttpClient/Tests/TestLogger.php @@ -19,6 +19,6 @@ class TestLogger extends AbstractLogger public function log($level, $message, array $context = []): void { - $this->logs[] = $message; + $this->logs[] = preg_replace_callback('!\{([^\}\s]++)\}!', static fn ($m) => $context[$m[1]] ?? $m[0], $message); } } 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