fix(HttpClient): let local curl set encoding based what it is built with#53605
fix(HttpClient): let local curl set encoding based what it is built with#53605joshtrichards wants to merge 1 commit intomasterfrom
Conversation
Previously we forced it to gzip but it's possible for a local curl: - not to have been built with gzip - to support additional encoding types In most cases this won't change behavior (i.e. gzip will still be used). Signed-off-by: Josh <[email protected]>
There was a problem hiding this comment.
Setting
$options['curl'][CURLOPT_ACCEPT_ENCODING] = '';tells libcurl to advertise all encodings it was built with (e.g. br, zstd, gzip, deflate).
However Guzzle’s response decoding is done in PHP, not by libcurl.
Guzzle only transparently decodes:
- gzip
- deflate
- br only if ext-brotli (brotli_uncompress()) is available
So this configuration can cause a real protocol mismatch:
- libcurl advertises br
- the server selects Content-Encoding: br
- PHP/Guzzle cannot decode it
- the client receives still-compressed bytes and treats them as plain text
That leads to:
- corrupted responses
- JSON decode failures
- empty or garbage payloads
- subtle data corruption with no explicit error
This is not theoretical — most PHP builds ship without ext-brotli, while libcurl in modern distros often supports Brotli and Zstd.
PR #55433 solves this correctly by advertising br only when PHP can actually decode it (function_exists('brotli_uncompress')), otherwise falling back to gzip, with full test coverage.
That keeps HTTP/2 + modern compression while guaranteeing that every negotiated encoding is safely decodable by Guzzle.
Summary
This is a mixture of a fix and an enhancement.
In the HTTP client, previously we forced
Accept-Encodingto gzip but it's possible for a local curl:In most cases this won't change behavior (i.e. gzip will still be used). In others, the specific server/client combo will simply choose something "better".
Notes:
Accept-Encodingdocumentation guzzle/guzzle#3215CURLOPT_ACCEPT_ENCODINGis the non-deprecated equivalent ofCURLOPT_ENCODINGChecklist