8000 [HttpClient] Header Content-Length missing when using callback as request-body · Issue #45965 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[HttpClient] Header Content-Length missing when using callback as request-body #45965
Closed
@SiebelsTim

Description

@SiebelsTim

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0