Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the comment regarding
CURLOPT_ENCODING
handling (#2904)
While researching how the `decode_content` option is meant to be used and looking into the Guzzle source code I stumbled over this part of the code, because it was non-obvious to me that providing an empty string to `CURLOPT_ENCODING` does not *disable* the decoding, but instead enables *all* decoders.
- Loading branch information
Showing
1 changed file
with
4 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -385,8 +385,11 @@ private function applyHandlerOptions(EasyHandle $easy, array &$conf): void | |
if ($accept) { | ||
$conf[\CURLOPT_ENCODING] = $accept; | ||
} else { | ||
// The empty string enables all available decoders and implicitly | ||
// sets a matching 'Accept-Encoding' header. | ||
$conf[\CURLOPT_ENCODING] = ''; | ||
// Don't let curl send the header over the wire | ||
// But as the user did not specify any acceptable encodings we need | ||
// to overwrite this implicit header with an empty one. | ||
$conf[\CURLOPT_HTTPHEADER][] = 'Accept-Encoding:'; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jtojnar
|
||
} | ||
} | ||
|
this header is incorrect. according to badly designed specs (i have no idea what the designers were thinking, the default is horrible!), when the user-agent does not specify any encodings, the server is free to choose any encoding it wishes. the correct way to specify no encoding whatsoever is
one famous example of a webserver choosing an encoding because the client didn't request any is Amazon.com