8000 [HttpClient] Fix computing stats for PUSH with Amp · symfony/symfony@8c01d78 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c01d78

Browse files
[HttpClient] Fix computing stats for PUSH with Amp
1 parent 1a12e12 commit 8c01d78

File tree

4 files changed

+50
-28
lines changed

4 files changed

+50
-28
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/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)
0