Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpClient] Overriding default option with null value is not working #45355

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

Closed
SosthenG opened this issue Feb 8, 2022 · 0 comments
Closed

Comments

@SosthenG
Copy link

SosthenG commented Feb 8, 2022

Symfony version(s) affected

4.4+

Description

When a default option is defined, it cannot be overridden by a null value in the $options parameter of the request method because of how HttpClientTrait::mergeDefaultOptions is working: using isset exclude every override with a null value.

I noticed the bug using the proxy option. In this case, passing false does disable the proxy, however the proxy option is expected to be a string or null so this is not really a good solution (and might cause issues with some implementations?)

How to reproduce

  • Define a proxy in framework.http_client.default_options
  • Try to disable the use of the proxy for a specific request by passing 'proxy' => null to the request options
  • The default option proxy is still used.

(Can probably be reproduced with any other options handled by the same isset condition)

Possible Solution

Use !array_key_exists($k, $options) instead of !isset($options[$k].
The documentation says about the options:

They can be defined globally in the configuration (to apply it to all requests) and to each request (which overrides any global configuration).

So any key that exists in the $options array should override the default options, no matter the value.

Additional Context

No response

@SosthenG SosthenG added the Bug label Feb 8, 2022
nicolas-grekas added a commit that referenced this issue Feb 24, 2022
…olas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] Fix overriding default options with null

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #45355
| License       | MIT
| Doc PR        | -

Commits
-------

37ac416 [HttpClient] Fix overriding default options with null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants