Skip to content

HttpClient Response->getInfo contains unredirected url when getContent is not called first #59284

@ThomasBerends

Description

@ThomasBerends

Symfony version(s) affected

7.2.1

Description

According to the ResponseInterface of the HttpClient, the getInfo call should contain "url (string) - the last effective URL of the request".

It does contain the url in both cases, but it returns the entered unredirected url when getContent() has not been called yet. If Response->getContent has been called, it will then return the correct url.

How to reproduce

Reproducer here: https://github.com/ThomasBerends/http_client_reproducable
There's two commands, app:expected and app:unexpected.

Expected:

$response = $this->httpClient->request('GET', "https://www.php.net/notfound");
// Fetch content
$response->getContent();
// Get the correct (redirected) url
dump($response->getInfo()['url']);
// "https://www.php.net/manual-lookup.php?pattern=notfound&lang=en&scope=404quickref"

Unexpected:

$response = $this->httpClient->request('GET', "https://www.php.net/notfound");
// Get the correct (redirected) url
dump($response->getInfo()['url']);
// "https://www.php.net/notfound"

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