-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Fix config for array of base_uri
in http_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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 6.4
Are you sure you want to change the base?
Conversation
Not sure about the xml conf, advices welcome! |
Can you please rebase on 6.3 since this is a bugfix? |
a6968d9
to
83ce0a9
Compare
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.') |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
base_uri
in http_client
Edit: Edit: Still got a problem with the way base uris are defined. On a fresh install in 6.3: # config/packages/framework.yaml
http_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')]
public function index(HttpClientInterface $testClient): Response
{
dump($testClient->request('GET', '/posts/1')->toArray());
// ...
} Results in a Any thought on how to do this? Conditional definition for both seems the most straightforward way, but I'm not sure about that |
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. |
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. |
In the meantime it needs to be rebased on 6.4 please |
Allow array of `base_uri` in config for HttpClient keys, as per [comment in PR](symfony#49809 (comment)).
Add optional `$baseUri` argument for `RetryableHttpClient::__construct` to allow proper integration in franework
e76e3ef
to
19a43c9
Compare
Okay there have been obviously a huge mistake on my part here... Fixing asap. |
Seems okay with the right destination branch. Sorry for the spam! |
Test failures seem unrelated here, but any advice would be welcome! |
Hey there! Bumping this, as it's still a missing feature. Should I create a new PR to get back in the recent ones? |
Hi @Tiriel, thanks for your patience. |
@@ -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 = []) |
There was a problem hiding this comment.
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
That's no problem to me, I'll go and change the PR description!
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:
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 ;) ) |
Also going to rebase and target the latest branch asap |
I think |
Then how do we deal with the I see four possibilities:
Personnally, I think the first option (blocking) or the last (merging) are the best, with a preference for the blocking. |
I would merge them: the base_uri is prepended to base_uris if any. |
Hum, actually no: we'd need to make setting both |
Alternatively, if we keep base_uri as allowing an array, we could make defining a WDYT? |
This seems like a better option to me, a bit more friendly to use
This seems a bit redundant. IIRC, In this case, I haven't looked at feasability yet, but maybe we could have a unified Seems a lot of work though, and not necessarily on the scope of this PR. |
Allow array of
base_uri
in config for HttpClient keys, as per comment in PR.