commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
GzipRequestMiddleware.php
1<?php
2
3
5
6use GuzzleHttp\Psr7\Utils;
7use Psr\Http\Message\RequestInterface;
8use 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=[])