Skip to content

Commit c909b7e

Browse files
bug #58953 [HttpClient] Fix computing stats for PUSH with Amp (nicolas-grekas)
This PR was merged into the 7.2 branch. Discussion ---------- [HttpClient] Fix computing stats for PUSH with Amp | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Tests with PUSH/vulcain fail after #58555. Computing stats for PUSH could be backported to lower versions, but let's keep things simple and consider this as an improvement, so not for lower branches. Commits ------- 792b970 [HttpClient] Fix computing stats for PUSH with Amp
2 parents 1a12e12 + 792b970 commit c909b7e

File tree

5 files changed

+51
-29
lines changed

5 files changed

+51
-29
lines changed

src/Symfony/Component/HttpClient/Response/AmpResponseV4.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,17 @@ private static function getPushedResponse(Request $request, AmpClientStateV4 $mu
433433
}
434434
}
435435

436+
$info += [
437+
'connect_time' => 0.0,
438+
'pretransfer_time' => 0.0,
439+
'starttransfer_time' => 0.0,
440+
'total_time' => 0.0,
441+
'namelookup_time' => 0.0,
442+
'primary_ip' => '',
443+
'primary_port' => 0,
444+
'start_time' => microtime(true),
445+
];
446+
436447
$pushDeferred->resolve();
437448
$logger?->debug(\sprintf('Accepting pushed response: "%s %s"', $info['http_method'], $info['url']));
438449
self::addResponseHeaders($response, $info, $headers);

src/Symfony/Component/HttpClient/Response/AmpResponseV5.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,17 @@ private static function getPushedResponse(Request $request, AmpClientStateV5 $mu
434434
}
435435
}
436436

437+
$info += [
438+
'connect_time' => 0.0,
439+
'pretransfer_time' => 0.0,
440+
'starttransfer_time' => 0.0,
441+
'total_time' => 0.0,
442+
'namelookup_time' => 0.0,
443+
'primary_ip' => '',
444+
'primary_port' => 0,
445+
'start_time' => microtime(true),
446+
];
447+
437448
$pushDeferred->complete();
438449
$logger?->debug(\sprintf('Accepting pushed response: "%s %s"', $info['http_method'], $info['url']));
439450
self::addResponseHeaders($response, $info, $headers);

src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -200,20 +200,20 @@ public function testHttp2PushVulcain()
200200

201201
$client->reset();
202202

203-
$expected = [
204-
'Request: "GET https://127.0.0.1:3000/json"',
205-
'Queueing pushed response: "https://127.0.0.1:3000/json/1"',
206-
'Queueing pushed response: "https://127.0.0.1:3000/json/2"',
207-
'Queueing pushed response: "https://127.0.0.1:3000/json/3"',
208-
'Response: "200 https://127.0.0.1:3000/json"',
209-
'Accepting pushed response: "GET https://127.0.0.1:3000/json/1"',
210-
'Response: "200 https://127.0.0.1:3000/json/1"',
211-
'Accepting pushed response: "GET https://127.0.0.1:3000/json/2"',
212-
'Response: "200 https://127.0.0.1:3000/json/2"',
213-
'Accepting pushed response: "GET https://127.0.0.1:3000/json/3"',
214-
'Response: "200 https://127.0.0.1:3000/json/3"',
215-
];
216-
$this->assertSame($expected, $logger->logs);
203+
$expected = <<<EOTXT
204+
Request: "GET https://127.0.0.1:3000/json"
205+
Queueing pushed response: "https://127.0.0.1:3000/json/1"
206+
Queueing pushed response: "https://127.0.0.1:3000/json/2"
207+
Queueing pushed response: "https://127.0.0.1:3000/json/3"
208+
Response: "200 https://127.0.0.1:3000/json" %f seconds
209+
Accepting pushed response: "GET https://127.0.0.1:3000/json/1"
210+
Response: "200 https://127.0.0.1:3000/json/1" %f seconds
211+
Accepting pushed response: "GET https://127.0.0.1:3000/json/2"
212+
Response: "200 https://127.0.0.1:3000/json/2" %f seconds
213+
Accepting pushed response: "GET https://127.0.0.1:3000/json/3"
214+
Response: "200 https://127.0.0.1:3000/json/3" %f seconds
215+
EOTXT;
216+
$this->assertStringMatchesFormat($expected, implode("\n", $logger->logs));
217217
}
218218

219219
public function testPause()
@@ -288,19 +288,19 @@ public function testHttp2PushVulcainWithUnusedResponse()
288288

289289
$client->reset();
290290

291-
$expected = [
292-
'Request: "GET https://127.0.0.1:3000/json"',
293-
'Queueing pushed response: "https://127.0.0.1:3000/json/1"',
294-
'Queueing pushed response: "https://127.0.0.1:3000/json/2"',
295-
'Queueing pushed response: "https://127.0.0.1:3000/json/3"',
296-
'Response: "200 https://127.0.0.1:3000/json"',
297-
'Accepting pushed response: "GET https://127.0.0.1:3000/json/1"',
298-
'Response: "200 https://127.0.0.1:3000/json/1"',
299-
'Accepting pushed response: "GET https://127.0.0.1:3000/json/2"',
300-
'Response: "200 https://127.0.0.1:3000/json/2"',
301-
'Unused pushed response: "https://127.0.0.1:3000/json/3"',
302-
];
303-
$this->assertSame($expected, $logger->logs);
291+
$expected = <<<EOTXT
292+
Request: "GET https://127.0.0.1:3000/json"
293+
Queueing pushed response: "https://127.0.0.1:3000/json/1"
294+
Queueing pushed response: "https://127.0.0.1:3000/json/2"
295+
Queueing pushed response: "https://127.0.0.1:3000/json/3"
296+
Response: "200 https://127.0.0.1:3000/json" %f seconds
297+
Accepting pushed response: "GET https://127.0.0.1:3000/json/1"
298+
Response: "200 https://127.0.0.1:3000/json/1" %f seconds
299+
Accepting pushed response: "GET https://127.0.0.1:3000/json/2"
300+
Response: "200 https://127.0.0.1:3000/json/2" %f seconds
301+
Unused pushed response: "https://127.0.0.1:3000/json/3"
302+
EOTXT;
303+
$this->assertStringMatchesFormat($expected, implode("\n", $logger->logs));
304304
}
305305

306306
public function testDnsFailure()

src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function shouldRetry(AsyncContext $context, ?string $responseContent, ?Tr
176176
$this->assertSame('Could not resolve host "does.not.exists".', $e->getMessage());
177177
}
178178
$this->assertCount(2, $logger->logs);
179-
$this->assertSame('Try #{count} after {delay}ms: Could not resolve host "does.not.exists".', $logger->logs[0]);
179+
$this->assertSame('Try #1 after 0ms: Could not resolve host "does.not.exists".', $logger->logs[0]);
180180
}
181181

182182
public function testCancelOnTimeout()

src/Symfony/Component/HttpClient/Tests/TestLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ class TestLogger extends AbstractLogger
1919

2020
public function log($level, $message, array $context = []): void
2121
{
22-
$this->logs[] = $message;
22+
$this->logs[] = preg_replace_callback('!\{([^\}\s]++)\}!', static fn ($m) => $context[$m[1]] ?? $m[0], $message);
2323
}
2424
}

0 commit comments

Comments
 (0)
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