-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpClient] add AsyncDecoratorTrait to ease processing responses without breaking async #36779
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
9f5fd61
to
61a0942
Compare
61a0942
to
d1dcf66
Compare
src/Symfony/Component/HttpClient/Response/PluggableResponse.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpClient/Response/PluggableResponse.php
Outdated
Show resolved
Hide resolved
d1dcf66
to
e31b716
Compare
e31b716
to
3f875a1
Compare
5b2b058
to
6438099
Compare
33e2614
to
f6e0252
Compare
The entry-point is now I implemented test cases that illustrate some use cases:
This is what made me change the API proposed here. PR ready. |
7551c8a
to
5b70e5f
Compare
Could this trait be used to solve #36967? 🤔 |
@derrabus absolutely: it would make it way easier to persist to the cache without breaking async. (bold claim, to be verified of course :) ) |
a730dfc
to
e65bfa2
Compare
I'm quite happy with this! BTW, doc PR at symfony/symfony-docs#13736 |
e65bfa2
to
5b0d5d4
Compare
5b0d5d4
to
0756aa7
Compare
@symfony/mergers I'd appreciate if we could merge this PR soon as that would unlock some next steps (I'm preparing a PR to allow pausing a response, needed for #36692 and for implementing support for HTTP 429 or throttling) |
…hout breaking async
0756aa7
to
766a1c6
Compare
*/ | ||
public function pause(float $duration): void | ||
{ | ||
if (\is_callable($pause = $this->response->getInfo('pause_handler'))) { |
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 anticipates #37136 to support pausing requests/responses
Thank you @nicolas-grekas. |
…oratorTrait (nicolas-grekas) This PR was merged into the 5.2 branch. Discussion ---------- [HttpClient] add doc about extending and AsyncDecoratorTrait About symfony/symfony#36779 and symfony/symfony#37136 Commits ------- f41ef12 [HttpClient] add doc about extending and AsyncDecoratorTrait
This PR allows processing the stream of chunks.
Some ideas:
Any custom logic should fit into the
$passthru
filter iterator (the last constructor argument ofAsyncResponse
). There, one has access to anAsyncContext
DTO, which allows controlling the stream, eg. to replace the current request/response, to change the passthru filter itself, etc.The surrounding logic will catch badly behaving filters to ease spotting some mistakes (eg. never forwarding an "isLast()" chunk, or yielding extra chunks after an "isLast()" one, etc.)
For the record:
previous_info
entry. I considered merging all internalresponse_headers
info under the main one since that's possible, but I'm not sure it's worth the added complexity. Please tell me if you think we should do it.usleep()
, but this doesn't play really well with async. Implementing small pauses and summing them up to the target pause might be good enough - we'll need to give it a try to know better.