Skip to content

[HttpClient] URL with colon is not correctly parsed #54332

Closed as not planned
Closed as not planned
@garak

Description

@garak

Symfony version(s) affected

6.4 and 7.0

Description

I'm using Google API for address validation. As referenced in their documentation, the URL to call is /v1:validateAddress

The problem is that HTTP client is trying to parse the URL without including the domain, so the part before the colon is interpreted as a schema, resulting in a "Unsupported scheme" HTTPException.

How to reproduce

Define an HTTP client like this:

framework:
    http_client:
        scoped_clients:
            map_address.client:
                base_uri: 'https://addressvalidation.googleapis.com/'
                headers:
                    content-type: 'application/json'
                    accept: 'application/json'

then inject your client as HttpClientInterface $mapAddressClient and try to use it:

$response = $this->mapAddressClient->request('POST', 'v1:validateAddress?key='.$myKey, [/* some data */]);

You'll get a Symfony\Component\HttpKernel\Exception\ HttpException Unsupported scheme in "v1:validateAddress?key=<redacted>

Possible Solution

I guess that the parsing of the URL done in

private static function parseUrl(string $url, array $query = [], array $allowedSchemes = ['http' => 80, 'https' => 443]): array
should be always done using the full URL, including the schema and the domain, so basically including the configured "base_uri" option.

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