[2.7] Add support for keeping boolean values "as is" in query

Merged
SI
2y ago
+17-7

I've stumbled upon this for like milion times now.

This is a follow up of https://github.com/guzzle/psr7/pull/391

Currently, there's no way not to cast boolean values to int in a query. http_build_query() casts booleans to ints, however, that is not always the wanted behaviour when constructing a query to call some API.

E.g. Swagger sends =true =false for params of type boolean. There are APIs that require this value format (e.g. https://github.com/PowerDNS/pdns).

This has been discussed many times over and over and the conclusion I make of it is that the behaviour should be configurable since it depends on the target API (e.g. see https://github.com/OpenAPITools/openapi-generator/issues/2204).

Therefore, I propose a flag that allows switch the behaviour in Query::build(). It should be BC compatible with the default value.