-
Notifications
You must be signed in to change notification settings - Fork 567
bisect: advertise gzip,deflate encoding when supported #5434
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: 2.1.x
Are you sure you want to change the base?
Changes from all commits
8133e71
ff7fe8d
810a43b
60457f0
7c4b805
97e5b10
dcc038f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,28 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| <?php declare(strict_types = 1); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| namespace PHPStan\Internal; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| use GuzzleHttp\Client; | ||||||||||||||||||||||||||||||||||||||||||||
| use function extension_loaded; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| final class HttpClientFactory | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * @param array<mixed> $config | ||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||
| * @see \GuzzleHttp\RequestOptions | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| public static function createClient(array $config): Client | ||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be a service, not a static function. So we can pass options from config parameters |
||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||
| !isset($config['headers']['Accept-Encoding']) | ||||||||||||||||||||||||||||||||||||||||||||
| && extension_loaded('zlib') | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| && extension_loaded('zlib') | |
| && extension_loaded('zlib') | |
| && ( | |
| !\array_key_exists(\GuzzleHttp\RequestOptions::DECODE_CONTENT, $config) | |
| || $config[\GuzzleHttp\RequestOptions::DECODE_CONTENT] !== false | |
| ) |
Copilot
AI
Apr 9, 2026
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.
isset($config['headers']['Accept-Encoding']) assumes headers is an array and only checks one exact casing. If a caller passes headers as a non-array (or uses a different header key casing), this can throw or result in duplicate Accept-Encoding values. Consider validating headers is an array and performing a case-insensitive presence check before setting the default.
| if ( | |
| !isset($config['headers']['Accept-Encoding']) | |
| && extension_loaded('zlib') | |
| ) { | |
| $hasAcceptEncodingHeader = false; | |
| if (isset($config['headers']) && is_array($config['headers'])) { | |
| foreach (array_keys($config['headers']) as $headerName) { | |
| if (is_string($headerName) && strcasecmp($headerName, 'Accept-Encoding') === 0) { | |
| $hasAcceptEncodingHeader = true; | |
| break; | |
| } | |
| } | |
| } | |
| if ( | |
| !$hasAcceptEncodingHeader | |
| && extension_loaded('zlib') | |
| ) { | |
| if (!isset($config['headers']) || !is_array($config['headers'])) { | |
| $config['headers'] = []; | |
| } |
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.
PHPDoc type
array<mixed>implies an int-keyed list; this config is an associative options array (RequestOptions keys). Consider changing toarray<string, mixed>(or a more specific shape) so static analysis keeps key type information.