-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] change the way http clients are configured by leveraging ScopingHttpClient #30674
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
Conversation
1fb972a
to
2580204
Compare
What do you think about using the same concept as the So someone could match on headers (like content-type / accept and even if the header is already present) or even body response ? |
I suppose you mean body request? |
2580204
to
86ea4b4
Compare
->cannotBeEmpty() | ||
->end() | ||
->scalarNode('base_uri') | ||
->info('The URI to resolve relative URLs, following rules in RFC 3985, section 2.') |
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 is not the full purpose of this option. Well, it IS the full purpose if scope
is not defined :p. But assuming it's not defined, this is both the base URI to use, but also for matching. Gotta find a way to "squeeze" that in. We could add an info
on the parent scopes
node?
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.
info updated
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Resources/config/http_client.xml
Outdated
Show resolved
Hide resolved
5bd1967
to
ab34374
Compare
Status: needs review |
51126c4
to
56b6bae
Compare
(failure is unrelated: some old commit for contracts us checked out) |
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.
+1 from a feature standpoint - I chatted about this with Nicolas.
<argument type="service" id="http_client" /> | ||
<argument type="collection" /> | ||
</service> | ||
<service id="Symfony\Contracts\HttpClient\HttpClientInterface $scopingHttpClient" alias="scoping_http_client" /> |
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.
So, a scoped HTTP client is the result, but $scopingHttpClient
does not sound good here.
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 thought that $scopedHttpClient
sounded like it was already "scoped". But really, this gives you a big object that is aware of all of the scopes, and has the ability to scope, based on the URI. The naming came from this thinking, but maybe it's still confusing?
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.
What Ryan said. The same reasoning is why ScopingHttpClient, the class, is named that way also.
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.
Still not a big fan of the names, but I don't have a better alternative.
…aging ScopingHttpClient
56b6bae
to
f1a26b9
Compare
I removed the |
…igured by leveraging ScopingHttpClient (nicolas-grekas) This PR was merged into the 4.3-dev branch. Discussion ---------- [FrameworkBundle] change the way http clients are configured by leveraging ScopingHttpClient | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This PR allows configuring scoped HTTP clients ("scoped_clients" replaces the previous "clients" options): ```yaml framework: http_client: max_host_connections: 4 default_options: # ... scoped_clients: github_client: base_uri: https://api.github.com headers: Authorization: token abc123 # ... ``` The base URI is turned into a scoping regular expression so that the token will be sent only when the `github_client` service is requesting the corresponding URLs. When the base URI is too restrictive, the `scope` option can be used explicitly to define the regexp that URLs must match before any other options are applied. ~All defined scopes are passed to a new `scoping_http_client` service, that can be used to hit endpoints with authentication pre-configured for several hosts. Its named autowiring alias is `HttpClientInterface $scopingClient` (this cannot be done with `http_client` as we want safe defaults, e.g. credentials should not be used implicitly when writing webhooks/crawlers.)~ Commits ------- f1a26b9 [FrameworkBundle] change the way http clients are configured by leveraging ScopingHttpClient
This PR allows configuring scoped HTTP clients ("scoped_clients" replaces the previous "clients" options):
The base URI is turned into a scoping regular expression so that the token will be sent only when the
github_client
service is requesting the corresponding URLs.When the base URI is too restrictive, the
scope
option can be used explicitly to define the regexp that URLs must match before any other options are applied.All defined scopes are passed to a newscoping_http_client
service, that can be used to hit endpoints with authentication pre-configured for several hosts. Its named autowiring alias isHttpClientInterface $scopingClient
(this cannot be done withhttp_client
as we want safe defaults, e.g. credentials should not be used implicitly when writing webhooks/crawlers.)