Skip to content

[HttpClient] Various cleanups after recent changes #58969

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

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 5.4
Bug fix? no
New feature? no
Deprecations? no
Issues -
License MIT

Recent changes motivated by security issues made me deep dive into the code of HttpClient again.
Here are some cleanups I'd like to do on branch 5.4

@@ -117,11 +117,20 @@ public function getHeaders(bool $throw = true): array

public function getInfo(?string $type = null)
{
if ('debug' === ($type ?? 'debug')) {
$debug = implode('', array_column($this->info['previous_info'] ?? [], 'debug'));
Copy link
Member Author

Choose a reason for hiding this comment

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

the debug info for AsyncResponse should contain all debug statements from previous requests, otherwise it's difficult to debug (happened to me)

@@ -291,6 +301,9 @@ public static function stream(iterable $responses, ?float $timeout = null, ?stri
}
}

if (null === $chunk) {
throw new \LogicException(\sprintf('"%s" is not compliant with HttpClientInterface: its "stream()" method didn\'t yield any chunks when it should have.', get_debug_type($client)));
Copy link
Member Author

Choose a reason for hiding this comment

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

this can happen when a phpunit mock is used instead of a MockHttpClient

if (null !== $ip = $multi->dnsCache->hostnames[$url['host'] = strtolower($url['host'])] ?? null) {
// Populate DNS cache for redirects if needed
$port = $url['port'] ?? ('http' === $url['scheme'] ? 80 : 443);
curl_setopt($ch, \CURLOPT_RESOLVE, ["{$url['host']}:$port:$ip"]);
Copy link
Member Author

Choose a reason for hiding this comment

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

CURLOPT_RESOLVE cannot be changed in the middle of a curl transaction so this is confusing dead code

});

return $previousHttpClient;
return new MockHttpClient(new MockResponse($content, ['primary_ip' => $ipAddr]));
Copy link
Member Author

Choose a reason for hiding this comment

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

phpunit mocks...

// the DNS cache respectively
'on_progress' => null, // callable(int $dlNow, int $dlSize, array $info) - throwing any exceptions MUST abort the
// request; it MUST be called on connection, on headers and on completion; it SHOULD be
// called on upload/download of data and at least 1/s
Copy link
Member Author

Choose a reason for hiding this comment

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

Reverting to the previous (before the latest CVE) signature for the progress function: it's way more seamless to expose the resolve function as an implementation detail using the info array.

@nicolas-grekas nicolas-grekas force-pushed the hc-cleanup branch 2 times, most recently from 12adc67 to f2efa4d Compare November 22, 2024 15:35
@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Nov 22, 2024

Failures on Windows are new to branch 5.4, I don't have them in v5.4.47
I'm going to have a closer look.

@nicolas-grekas
Copy link
Member Author

#58915 introduced the issue on Windows 🔍

@nicolas-grekas nicolas-grekas force-pushed the hc-cleanup branch 3 times, most recently from 6b415a1 to c444d7c Compare November 25, 2024 09:10
@nicolas-grekas nicolas-grekas merged commit 5cbdb87 into symfony:5.4 Nov 25, 2024
10 of 11 checks passed
nicolas-grekas added a commit that referenced this pull request Nov 26, 2024
This PR was merged into the 7.2 branch.

Discussion
----------

[HttpClient] fix amphp/http-client 5 support

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | following #58969
| License       | MIT

Commits
-------

06e56f8 fix amphp/http-client 5 support
@nicolas-grekas nicolas-grekas deleted the hc-cleanup branch January 3, 2025 16:26
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.

2 participants