Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpClient] Header Content-Length missing when using callback as request-body #45965

Copy link
Copy link
Closed
@SiebelsTim

Description

@SiebelsTim
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.