Description
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