Closed
Description
Symfony version(s) affected
6.1.6
Description
When sending a request with symfony http-client and the body in the options array is an array, the content-type is always set to application/x-www-form-urlencoded
even if I explicitly set another content-type.
I need to set charset on the content type like this Content-Type: application/x-www-form-urlencoded; charset=utf-8
, but it gets overridden.
How to reproduce
$response = $this->client->request('POST', '/create', [
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'
],
'body' => ['key' => 'value']
]);
$response->getContent();
// We can see here that the Content-Type header is "application/x-www-form-urlencoded" and not "application/x-www-form-urlencoded; charset=utf-8"
$debugInfo = $response->getInfo('debug')
Possible Solution
Remove these lines or add a check if the header is already set.
Additional Context
Looks like this was introduced in #45812 but I do not understand the reasoning behind doing it. I should be able to set the header I want. at least be able to set charset.
A workaround for me is to normalize the body into a string my self, but I should not have to do that in my opinion.