Skip to content

[HttpClient] NoPrivateNetworkHttpClient with max_redirects = 0 returns empty content an the second call #59574

Closed
@glaubinix

Description

@glaubinix

Symfony version(s) affected

6.4.17 / 7.2.2

Description

Calling getContent twice on the AsyncResponse returned by the NoPrivateNetworkHttpClient returns an empty string the second time the method is called if the NoPrivateNetworkHttpClient is configured with the following options: ['max_redirects' => 0].

This works fine with symfony/http-client 6.4.15 and 6.4.16

How to reproduce

$httpClient = new \Symfony\Component\HttpClient\NoPrivateNetworkHttpClient(\Symfony\Component\HttpClient\HttpClient::create());
$httpClient = $httpClient->withOptions(['max_redirects' => 0]);
$response = $httpClient->request('GET', 'https://example.com');

$content1 = $response->getContent(); // $content1 will be the HTML body
$content2 = $response->getContent(); // $content2 will be an empty string

Possible Solution

Obviously not a solution but this works ok if I remove the return AsyncResponse(... that was added in line 120 in this commit symfony/http-client@d77d8e2

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