commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
GzipRequestMiddleware.php
1 <?php
2 
3 
4 namespace Commercetools\Client;
5 
6 use GuzzleHttp\Psr7\Utils;
7 use Psr\Http\Message\RequestInterface;
8 use function gzencode;
9 
11 {
12  public static function gzipEnabled(): bool
13  {
14  return function_exists('gzencode');
15  }
16 
17  public function __invoke(RequestInterface $request, array $options = []): RequestInterface
18  {
19  $content = gzencode($request->getBody()->getContents());
20  $request = Utils::modifyRequest($request, [
21  'body' => $content,
22  'set_headers' => [
23  'Content-Encoding' => 'gzip',
24  'Content-Length' => strlen($content),
25  ],
26  ]);
27  return $request;
28  }
29 }
__invoke(RequestInterface $request, array $options=[])