Skip to content

[HttpClient] Fix computing stats for PUSH with Amp #58953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Symfony/Component/HttpClient/Response/AmpResponseV4.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/HttpClient/Response/AmpResponseV5.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
54 changes: 27 additions & 27 deletions src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<<EOTXT
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" %f seconds
Accepting pushed response: "GET https://127.0.0.1:3000/json/1"
Response: "200 https://127.0.0.1:3000/json/1" %f seconds
Accepting pushed response: "GET https://127.0.0.1:3000/json/2"
Response: "200 https://127.0.0.1:3000/json/2" %f seconds
Accepting pushed response: "GET https://127.0.0.1:3000/json/3"
Response: "200 https://127.0.0.1:3000/json/3" %f seconds
EOTXT;
$this->assertStringMatchesFormat($expected, implode("\n", $logger->logs));
}

public function testPause()
Expand Down Expand Up @@ -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 = <<<EOTXT
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" %f seconds
Accepting pushed response: "GET https://127.0.0.1:3000/json/1"
Response: "200 https://127.0.0.1:3000/json/1" %f seconds
Accepting pushed response: "GET https://127.0.0.1:3000/json/2"
Response: "200 https://127.0.0.1:3000/json/2" %f seconds
Unused pushed response: "https://127.0.0.1:3000/json/3"
EOTXT;
$this->assertStringMatchesFormat($expected, implode("\n", $logger->logs));
}

public function testDnsFailure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpClient/Tests/TestLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading