Replies: 2 comments
|
Ping @nicolas-grekas as GIT hinted that you recently worked on it :-) |
|
This is a decoration order issue: with A higher decoration priority means "closer to the transport". Scoped clients are built as a decoration stack: At the default priority of 0, your decorator sits outside all of these. It therefore sees the raw Give the decorator a priority above the others so that it sits close to the transport: foo.client.private:
class: Symfony\Component\HttpClient\NoPrivateNetworkHttpClient
decorates: 'foo.client'
decoration_priority: 200
arguments: ['@.inner']
That placement is also the one you want for the check itself. As the outermost decorator, One case is not covered by reordering: options declared under |
Uh oh!
There was an error while loading. Please reload this page.
Within a Symfony v8.1.5 project we have a scoped client defined in
http_client.yaml, withmax_redirects: 0(named:foo.client)As services we have:
The goal: we wrap the
foo.clientwithin aNoPrivateNetworkHttpClientwhich would not allow to connect to external networks.The Problem
When triggering a request by using the
foo.client.privatewe noticed that the original client'smax_redirectsis not respected, and multiple redirects are handled.Digging into the issue:
The
NoPrivateNetworkHttpClient::request(string $method, string $url, array $options = [])method builds the final set of options to use for the subsquent request as follows:See: https://github.com/symfony/symfony/blob/8.2/src/Symfony/Component/HttpClient/NoPrivateNetworkHttpClient.php#L80
This is merging the
$optionsparameter of the method, and its own default options (and fallback toHttpClientInterface::OPTIONS_DEFAULTS, which hasmax_redirects => 20).This then triggers the inner-client request processing. The problem is that the
max_redirectsis passed with "20" as merged from the local configurations. This ignores the initial configuration provided forfoo.client, thus following more than0redirects.Temporary Solution
The temporary solution is to invoke
$fooClientPrivate->request()and pass thatmax_redirectsagain:Is this a known issue, or should I create a proper bug/feature for the component?
Any advice here?
All reactions