Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FrameworkBundle] Fix config for array ofbase_uri inhttp_client#53131

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Tiriel wants to merge6 commits intosymfony:6.4
base:6.4
Choose a base branch
Loading
fromTiriel:fix/http-client-configuration

Conversation

Tiriel
Copy link
Contributor

@TirielTiriel commentedDec 18, 2023
edited
Loading

QA
Branch?6.4
Bug fix?yes
New feature?yes
Deprecations?no
Issuesno
LicenseMIT

Allow array ofbase_uri in config for HttpClient keys, as percomment in PR.

@Tiriel
Copy link
ContributorAuthor

Not sure about the xml conf, advices welcome!

@nicolas-grekas
Copy link
Member

Can you please rebase on 6.3 since this is a bugfix?

Tiriel reacted with thumbs up emoji

@TirielTirielforce-pushed thefix/http-client-configuration branch froma6968d9 to83ce0a9CompareDecember 19, 2023 08:38
@TirielTiriel changed the base branch from7.1 to6.3December 19, 2023 08:39
@Tiriel
Copy link
ContributorAuthor

Rebased on 6.3!

@@ -1901,13 +1901,17 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode, callable $e
->ifTrue(function ($v) { return !empty($v['query']) && !isset($v['base_uri']); })
->thenInvalid('"query" applies to "base_uri" but no base URI is defined.')
->end()
->validate()
->ifTrue(fn ($v) => (isset($v['base_uri']) && \is_array($v['base_uri'])) && !isset($v['retry_failed']))
->thenInvalid('"base_uri" can only be an array if "retry_failed" is defined.')

Choose a reason for hiding this comment

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

defined or enabled for retry_failed?
also, should we validate the array contains only strings?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I'd say that more precautions are always better, so indeed checking if there are strings only!
And yeah, retries should be enabled, imo.

Going to make changes in that direction.

Copy link
Member

Choose a reason for hiding this comment

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

In this code we're merging all validations but the error message is the same for all. If you define an array and one of the values is no a string by mistake, you'll see this and will be confusing:

"base_uri" can only be an array if "retry_failed" is defined

Maybe we could extract this validation and create a dedicated error message for it?

\count($v['base_uri']) !==\count(array_filter($v['base_uri'],'is_string'))

Thanks!

@OskarStarkOskarStark changed the title[FrameworkBundle] Fix config for array of base_uri in http_client[FrameworkBundle] Fix config for array ofbase_uri inhttp_clientDec 19, 2023
@Tiriel
Copy link
ContributorAuthor

Tiriel commentedDec 19, 2023
edited
Loading

Edit: Edit: Still got a problem with the way base uris are defined.
Configuration-wise the proposed changes seem to work. But not in the field.

On a fresh install in 6.3:

# config/packages/framework.yamlhttp_client:scoped_clients:test_client:base_uri:                    -'https://jsonplaceholder.typicode.com/'                    -'https://jsonplaceholder.typicode.com/'retry_failed:max_retries:3
// in any controller    #[Route('/', name:'app_client')]publicfunctionindex(HttpClientInterface$testClient):Response    {dump($testClient->request('GET','/posts/1')->toArray());// ...    }

Results in aTypeError: Symfony\Component\HttpClient\ScopingHttpClient::forBaseUri(): Argument #2 ($baseUri) must be of type string, array given since thebase_uri are passed when creating theScopingHttpClient and not theRetryableHttpClient.

Any thought on how to do this? Conditional definition for both seems the most straightforward way, but I'm not sure about that

@Tiriel
Copy link
ContributorAuthor

Made an attempt just as a discussion base. Works as is, but maybe there's a better way to do it or some constraints I haven't tought about.

@nicolas-grekasnicolas-grekas modified the milestones:6.3,6.4Feb 1, 2024
@Tiriel
Copy link
ContributorAuthor

Hey there!

Sorry for the ping, I know it's been a while, but could I interest you back in a review around here?@nicolas-grekas maybe, or someone else? This was asked in an issue so maybe we should look into it.

@OskarStark
Copy link
Contributor

OskarStark commentedApr 24, 2024
edited
Loading

In the meantime it needs to be rebased on 6.4 please

Tiriel reacted with thumbs up emoji

Allow array of `base_uri` in config for HttpClient keys, as per[comment in PR](symfony#49809 (comment)).
@TirielTirielforce-pushed thefix/http-client-configuration branch frome76e3ef to19a43c9CompareApril 25, 2024 14:59
@Tiriel
Copy link
ContributorAuthor

Okay there have been obviously a huge mistake on my part here... Fixing asap.

@TirielTiriel changed the base branch from6.3 to6.4April 25, 2024 15:00
@Tiriel
Copy link
ContributorAuthor

Seems okay with the right destination branch. Sorry for the spam!

@Tiriel
Copy link
ContributorAuthor

Test failures seem unrelated here, but any advice would be welcome!

@Tiriel
Copy link
ContributorAuthor

Hey there!

Bumping this, as it's still a missing feature. Should I create a new PR to get back in the recent ones?

@lyrixxlyrixx removed their request for reviewAugust 13, 2024 08:09
@nicolas-grekas
Copy link
Member

Hi@Tiriel, thanks for your patience.
I think I changed my mind on the topic: this looks like a new feature to me.
To built on this idea, I'm wondering if it wouldn't make more sense to allow a newbase_uris option underretry_failed.
That would make everything simpler I think.

@@ -39,12 +39,13 @@ class RetryableHttpClient implements HttpClientInterface, ResetInterface
/**
* @param int $maxRetries The maximum number of times to retry
*/
public function __construct(HttpClientInterface $client, ?RetryStrategyInterface $strategy = null, int $maxRetries = 3, ?LoggerInterface $logger = null)
public function __construct(HttpClientInterface $client, ?RetryStrategyInterface $strategy = null, int $maxRetries = 3, ?LoggerInterface $logger = null, array $baseUris = [])

Choose a reason for hiding this comment

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

this change is not needed nor used

@nicolas-grekasnicolas-grekas modified the milestones:6.4,7.2Aug 21, 2024
@Tiriel
Copy link
ContributorAuthor

Hi@Tiriel, thanks for your patience. I think I changed my mind on the topic: this looks like a new feature to me.

That's no problem to me, I'll go and change the PR description!

To built on this idea, I'm wondering if it wouldn't make more sense to allow a newbase_uris option underretry_failed. That would make everything simpler I think.

Not sure about that though. I don't know if it's a better idea or not, but I'm not sure about what we should priorize:

  • consistency (keep thebase_uri option where it is already defined for the scoped clients)
  • intent behind the change (allow to try multiple uris in case of retry)

Both seem to have pros and cons to me, but ultimately I'll get behind the majority advice (or your, if there not much debate ;) )

@Tiriel
Copy link
ContributorAuthor

Also going to rebase and target the latest branch asap

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedAug 22, 2024
edited
Loading

I thinkbase_uris underretry_strategy is more flexible as it allows usingscope on top to control how scoped clients behave

@Tiriel
Copy link
ContributorAuthor

Then how do we deal with thebase_uri option under each scoped client? Unless I miss something, it would be possible to define abase_uri in a scope client and an array ofbase_uris in theretry_strategy.

I see four possibilities:

  • adding abase_uri under the scoped client and an array ofbase_uris in the retry strategy is blocked, raising an exception
  • adding abase_uri under the scoped client and an array ofbase_uris in the retry strategy isnot blocked, base uri from scoped client is kept
  • adding abase_uri under the scoped client and an array ofbase_uris in the retry strategy isnot blocked, base uris from retry strategy are kept
  • adding abase_uri under the scoped client and an array ofbase_uris in the retry strategy isnot blocked, base uri from scoped client is merged inside the array

Personnally, I think the first option (blocking) or the last (merging) are the best, with a preference for the blocking.

@nicolas-grekas
Copy link
Member

I would merge them: the base_uri is prepended to base_uris if any.

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedAug 22, 2024
edited
Loading

Hum, actually no: we'd need to make setting bothbase_uri andbase_uris conflict, and we'd then need to compute a regular expression that "|" allbase_uris so that scoped clients accepts them all in its scope (unlessscope is set).

@nicolas-grekas
Copy link
Member

Alternatively, if we keep base_uri as allowing an array, we could make defining aretry_strategy optional (and auto-enable it then).
We also need to allow setting both ascope and an array ofbase_uris for completeness (both options are exclusive at the moment).

WDYT?

@Tiriel
Copy link
ContributorAuthor

Alternatively, if we keep base_uri as allowing an array, we could make defining aretry_strategy optional (and auto-enable it then).

This seems like a better option to me, a bit more friendly to use

We also need to allow setting both ascope and an array ofbase_uris for completeness (both options are exclusive at the moment).

This seems a bit redundant. IIRC,scope makes the configuration active only on uris matching the scope. So if you set an array of base uris and the scope, the scope will simply be active on every call since the base uris matching the scope will be prepended to each call.

In this case, I haven't looked at feasability yet, but maybe we could have a unifiedscope/base_uri option, working differently depending on the actual call you make: when callingrequest, if you pass a full uri with scheme/host, it works as scope, and if you pass a path, it prepends the base uri.

Seems a lot of work though, and not necessarily on the scope of this PR.

@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@javiereguiluzjaviereguiluzjaviereguiluz left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@ycerutoycerutoAwaiting requested review from yceruto

@chalasrchalasrAwaiting requested review from chalasr

@dunglasdunglasAwaiting requested review from dunglas

@OskarStarkOskarStarkAwaiting requested review from OskarStark

@jderussejderusseAwaiting requested review from jderusse

@xabbuhxabbuhAwaiting requested review from xabbuh

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

6 participants
@Tiriel@nicolas-grekas@OskarStark@javiereguiluz@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp