-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix(HttpClient): let local curl set encoding based what it is built with #53605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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 <josh.t.richards@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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