Skip to content

[HttpClient] should not encode best-practice characters in query-parameters (@:!;,*) #48315

Closed
@kohlerdominik

Description

@kohlerdominik

Symfony version(s) affected

6.1.7

Description

The http client currently uses http_build_query, which encodes way to many characters. More and more URLs use special characters like [ @ : ! ; , * ], as they are not http-relevant. I saw, that this characters are accepted by the Symfony Routing Component, for example: UrlGenerator::30

Real world example

I'm currently working with an API, that expects ISO8601 DateTime strings in the URL.

RFC3339 states, that

[ISO8601] dates SHOULD be used in new protocols on the Internet

So usage of ISO8601 is defintively encouraged.

But as the : characters is encoded by the HttpClient, the parameter looking like 2022-11-24T18:00:00 is getting encoded, and therefore not accepted by the backend.

How to reproduce

HttpClient::create()->request('GET', 'your-url', [
    'query' => [
        'dateTime' => '2022-11-24T18:00:00'
    ]
]);

Possible Solution

Instead of using http_build_query, use a similar implementation like Symfony\Component\Routing\Generator\UrlGenerator

Additional Context

Comparisions:

Browsers: Neither Microsoft Edge nor Firefox encode the characters above in URLs.
Postman also sends them without encoding.

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