Skip to content

Commit bb9a652

Browse files
committed
configure client to add acceptEncoding header
1 parent 45113cd commit bb9a652

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/commercetools-base/src/Client/ClientFactory.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@ private function createGuzzleClientWithOptions(array $options, array $middleware
7474
'verify' => true,
7575
'timeout' => 60,
7676
'connect_timeout' => 10,
77-
'pool_size' => 25
77+
'pool_size' => 25,
78+
'headers' => []
7879
],
7980
$options
8081
);
82+
if (!isset($options['headers']['accept-encoding']) && $this->acceptCompressedResponse()) {
83+
$options['headers']['accept-encoding'] = 'gzip';
84+
}
8185
if (!isset($options['headers']['user-agent'])) {
8286
$options['headers']['user-agent'] = (new UserAgentProvider())->getUserAgent();
8387
}
@@ -94,6 +98,15 @@ private function createGuzzleClientWithOptions(array $options, array $middleware
9498

9599
return $client;
96100
}
101+
102+
private function acceptCompressedResponse(): bool
103+
{
104+
if (function_exists('gzdecode')) {
105+
return true;
106+
}
107+
108+
return false;
109+
}
97110

98111
public static function of(): ClientFactory
99112
{

0 commit comments

Comments
 (0)