Replies: 1 comment 5 replies
-
Hello, as your decorator does not care about the response you should return the decorated service’s: public function request(string $method, string $url, array $options = []): ResponseInterface
{
return $this->client->request($method, $url, $options);
} (You do not need to |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
In my SF 5.4 app I have a scoped clients in
http_client.yaml
See http_client.yaml
See decorator class
I wrote a compiler pass to decorate my http clients
See MyCompilerPass.php
The problem is that now I get an empty content when calling my clients, e.g.
$firstClient->request('GET', '/users')->getContent(); // returns ""
. I did some debugging and the reason is that WithMyHeaderClientDecorator decorates the base client (http_client service) and all the scoped clients (that are also a decorators for the base client). This leads to the nested AsyncResponse returned fromrequest()
method. ThegetContent()
call on the nested instance returns an expected content but the same call on the outer instance returns empty string.Is it a bug in Symfony or my misunderstanding how/when to use AsyncResponse class (or/and AsyncDecoratorTrait?).
In my specific case I could just exclude
http_client
id from decoration in compiler pass and it will work but it's just a coincidence, because my case is simple. I could also (and probably should) just call the inner client'srequest()
method and forward the returned value from my decorator. But let's consider the problem with nested AsyncResponse instances. Let's remember that a client can be decorated multiple times (by me or by the vendor code) so I never know whether a client I decorate (directly or indirectly as another decorator in the decoration stack) with WithMyHeaderClientDecorator will return AsyncResponse instance fromrequest(): ResponseInterface
method (decoration considers only interface contract).Reproducer
See reproducer
Beta Was this translation helpful? Give feedback.
All reactions