Skip to content

HTTP client overrides multiple occurrences of same query parameter #31918

Closed
@devfrey

Description

@devfrey
  • Laravel Version: 7.1.0
  • PHP Version: 7.4.3
  • Database Driver & Version: irrelevant

Description:

I have a use case where I need to query an endpoint with multiple occurrences of the same query parameter. Guzzle supports this just fine if the query parameters are passed in the URL. Laravel's HTTP client, however, always extracts the query parameters from the URL and then passes them to Guzzle as an array. This results in the last occurrence overwriting all prior occurrences.

The endpoint in question is a Lucene/Solr instance that allows the fq query parameter to be specified multiple times. As far as I'm aware there's no standard regarding these query parameters so this should be a valid use case.

Unfortunately there's no way around this problem. Even with the bracket syntax (to indicate a query parameter with multiple values) Guzzle then turns it into a URL that is not supported by Solr.

Steps To Reproduce:

Make a request to an endpoint with multiple occurrences of the same query parameter and you'll see the last occurrence overwrites all previous ones:

Http::get('https://example.com/?fq=hello&fq=world');
// actual request goes to https://example.com/?fq=world

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions