Closed
Description
Symfony version(s) affected
5.4.7
Description
In #45814 the HTTP-Client was changed to only set the content-length via the CURLOPT_INFILE
option. However, that option is not used for CURLOPT_READFUNCTION
. For that we would need CURLOPT_POSTFIELDSIZE
which is not exposed in PHP (see php/php-src#8165).
As a result, when using a callback for the request's body, we cannot set the Content-Length header anymore.
In combination with resetting the Transfer-Encoding header to get curl to not send a chunked request, we cannot send a request with a body.
How to reproduce
<?php
use Symfony\Component\HttpClient\CurlHttpClient;
require_once __DIR__ . '/vendor/autoload.php';
$client = new CurlHttpClient([]);
$counter = 0;
$response = $client->request('POST', 'http://localhost:982/iserv/helloworld', [
'headers' => ['Content-Length' => [10000], 'Transfer-Encoding' => [' ']],
'body' => static function (int $length) use(&$counter){
if ($counter++ > 0) {
return "";
}
return str_repeat("A", 10000);
},
]);
echo $response->getContent();
Possible Solution
No response
Additional Context
No response