-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpClient] Allow enabling buffering conditionally with a Closure #32565
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
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.
Thanks for working on this :)
c915a31
to
f4ddd10
Compare
Could you please give me some tips to make sure the tests pass? I'm not sure how to fix them |
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.
Thanks :)
We also need to validate the regex and fail properly when it is not valid, can you add a test case ensuring so?
ec3e7bb
to
0452bf6
Compare
e2500ff
to
f1e77b1
Compare
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.
(no need for the return-type annotation on createBufferForContentType IMHO)
66c4079
to
917a8d9
Compare
Thanks, LGTM for the component. Could you please have a look at the configuration for the component in FrameworkBundle? |
917a8d9
to
7b33c42
Compare
Right now the default value of the buffer option is true, defined in Should I add this option in the configuration (both default_options and scoped_clients?) and validate it in the configuration? |
I'd say yes :) |
I added the buffer configuration option for both the default_options as the scoped_clients. Also updated the documentation in a PR |
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
Outdated
Show resolved
Hide resolved
f56174f
to
4eabdf4
Compare
96e1076
to
492d0d9
Compare
I would not make the regex configurable (as I don't see the use cases but I can see how one can mess up with changing the regex). The |
Ok. So what should happen with this PR? |
We are on the right track. The configuration option should only allow |
Ok. Any idea which content types we'll allow to be buffered automatically? I need this one to be able to build a regex |
src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
Outdated
Show resolved
Hide resolved
Why not the following solution: buffer: true
buffer_regex: '/([a-z]+\/json)/' buffer regex is containing the default one which could be overridden and is used if buffer is |
2c1cc5c
to
8486526
Compare
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 updated this PR to take @fabpot's comment into account. The option "buffer" is now removed from FrameworkBundle.
Implementations in the component (not the contracts) support a string
for the "buffer" option.
This string should be a regular expression that enables buffering when the content-type of the response matches it.
It defaults to #^(?:text/|application/(?:.+\+)?(?:json|xml)$)#i
, which covers all common content-types that should be buffered to me.
8486526
to
db9b15a
Compare
I figured out we could make this much more powerful by accepting a @rjwebdev could you please sync the PR description and the documentation PR? |
db9b15a
to
f705ac9
Compare
Since you removed the |
We'd need a new PR, to explain the option, in the doc for the component: |
Thank you @rjwebdev. |
…th a Closure (rjwebdev) This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] Allow enabling buffering conditionally with a Closure | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31883 | License | MIT | Doc PR | symfony/symfony-docs#12043 With this PR, responses can be buffered automatically from a closure passed to the `buffer` option. ```php $resp = $client->request('GET', $url, [ 'buffer' => function (array $headers): bool { return true/false; }, ]); ``` When no option is provided, buffering is now enabled only for json, xml and text/* content types. Commits ------- f705ac9 [HttpClient] Allow enabling buffering conditionally with a Closure
…ttp_client (rjwebdev) This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] Add buffer configuration option to http_client In PR symfony/symfony#32565, a regex value was added as a check to automatically buffer the content of a call. Since this is a new feature, the documentation of the http_client configuration true frameworkbundle is updated <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- 0f65736 Add buffer configuration option to http_client
With this PR, responses can be buffered automatically from a closure passed to the
buffer
option.When no option is provided, buffering is now enabled only for json, xml and text/* content types.