diff --git a/src/Command/BisectCommand.php b/src/Command/BisectCommand.php index 8cb0c0382d..6e49099a76 100644 --- a/src/Command/BisectCommand.php +++ b/src/Command/BisectCommand.php @@ -9,6 +9,7 @@ use Override; use PHPStan\Command\Bisect\BinarySearch; use PHPStan\File\FileReader; +use PHPStan\Internal\HttpClientFactory; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; @@ -106,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 1; } - $client = new Client([ + $client = HttpClientFactory::createClient([ RequestOptions::TIMEOUT => 30, RequestOptions::CONNECT_TIMEOUT => 10, 'headers' => [ diff --git a/src/Command/FixerApplication.php b/src/Command/FixerApplication.php index 8d6432258c..e08d752623 100644 --- a/src/Command/FixerApplication.php +++ b/src/Command/FixerApplication.php @@ -7,7 +7,6 @@ use DateTime; use DateTimeImmutable; use DateTimeZone; -use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\RequestOptions; use Nette\Utils\Json; @@ -23,6 +22,7 @@ use PHPStan\Internal\ComposerHelper; use PHPStan\Internal\DirectoryCreator; use PHPStan\Internal\DirectoryCreatorException; +use PHPStan\Internal\HttpClientFactory; use PHPStan\PhpDoc\StubFilesProvider; use PHPStan\Process\ProcessCanceledException; use PHPStan\Process\ProcessCrashedException; @@ -325,7 +325,7 @@ private function downloadPhar( $output->writeln('Checking if there\'s a new PHPStan Pro release...'); } - $client = new Client([ + $client = HttpClientFactory::createClient([ RequestOptions::TIMEOUT => 30, RequestOptions::CONNECT_TIMEOUT => 5, ]); diff --git a/src/Internal/HttpClientFactory.php b/src/Internal/HttpClientFactory.php new file mode 100644 index 0000000000..cf548fb7fe --- /dev/null +++ b/src/Internal/HttpClientFactory.php @@ -0,0 +1,28 @@ + $config + * + * @see \GuzzleHttp\RequestOptions + */ + public static function createClient(array $config): Client + { + if ( + !isset($config['headers']['Accept-Encoding']) + && extension_loaded('zlib') + ) { + $config['headers']['Accept-Encoding'] = 'gzip,deflate'; + } + + return new Client($config); + } + +}