Skip to content

[HttpClient] Scoped clients doesn't work with Caching HTTP Client #62166

@pierredup

Description

@pierredup

Symfony version(s) affected

7.4

Description

When using the Caching HTTP Client with a scoped client, an exception Invalid URL: scheme is missing is thrown on the request

How to reproduce

Either creating the scoped client manually:

$client = new CachingHttpClient(
    ScopingHttpClient::forBaseUri(HttpClient::create(), 'https://api.github.com'),
    new TagAwareAdapter(new ArrayAdapter()),
);

$release = $client->request('GET', '/repos/symfony/symfony/releases/latest');

or using the framework.yaml config:

framework:
    http_client:
        scoped_clients:
            github.client:
                base_uri: 'https://api.github.com'
                caching:
                    cache_pool: cache.app.taggable

When doing a request without the scheme and domain (E.G $release = $client->request('GET', '/repos/symfony/symfony/releases/latest');), the following exception is thrown:

Invalid URL: scheme is missing in "/repos/symfony/symfony/releases/latest". Did you forget to add "http(s)://"?

This is because the CachingHttpClient calls self::prepareRequest first thing in the request method, which validated the URL and throws the exception before giving the ScopingHttpClient a chance to set the base uri

[$fullUrl, $options] = self::prepareRequest($method, $url, $options, $this->defaultOptions);

cc: @Lctrs

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