Skip to content

[HttpClient] Fix streaming and redirecting with NoPrivateNetworkHttpClient #59023

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 28, 2024

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues #59021
License MIT

Copy link
Member Author

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With test cases to cover the regressions found on the happy path (aka no matches for the provided $subnets)

$onProgress = $options['on_progress'] ?? null;
$subnets = $this->subnets;
$ipFlags = $this->ipFlags;
$lastPrimaryIp = '';

$options['on_progress'] = static function (int $dlNow, int $dlSize, array $info) use ($onProgress, $subnets, $ipFlags, &$lastPrimaryIp): void {
if (($info['primary_ip'] ?? '') !== $lastPrimaryIp) {
if (!\in_array($info['primary_ip'] ?? '', ['', $lastPrimaryIp], true)) {
Copy link
Member Author

@nicolas-grekas nicolas-grekas Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix for the empty ip address error (it didn't happen before, but now that we redirect on our own, it can)

self::ipCheck($info['primary_ip'], $subnets, $ipFlags, null, $info['url']);
$lastPrimaryIp = $info['primary_ip'];
}

null !== $onProgress && $onProgress($dlNow, $dlSize, $info);
};

if (0 >= $maxRedirects = $options['max_redirects']) {
return new AsyncResponse($this->client, $method, $url, $options);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix when 0 >= $maxRedirects: the passthru callback shouldn't be used in this case

*/
public function stream($responses, ?float $timeout = null): ResponseStreamInterface
{
return $this->client->stream($responses, $timeout);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix for the stream() method: the one provided by AsyncDecoratorTrait is fine instead (I forgot to remove this one when adding the trait)

@@ -24,11 +24,6 @@ public static function setUpBeforeClass(): void
TestHttpServer::start();
}

public static function tearDownAfterClass(): void
{
TestHttpServer::stop();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one test server instance can handle all test cases, no need to start/stop it all the time

@@ -36,7 +36,6 @@ public static function tearDownAfterClass(): void
{
TestHttpServer::stop(8067);
TestHttpServer::stop(8077);
TestHttpServer::stop(8087);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to stop this port, it can handle many test cases
(8067 and 8077 are special because they test situations where the webserver hangs)

@nicolas-grekas
Copy link
Member Author

(Failures on deps=high are expected: this job checks out 4.4 and runs it with recent test cases)

@nicolas-grekas nicolas-grekas merged commit 7a2d66a into symfony:5.4 Nov 28, 2024
11 of 12 checks passed
@nicolas-grekas nicolas-grekas deleted the hc-fix branch November 28, 2024 14:06
This was referenced Nov 29, 2024
This was referenced Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants