From f3a62f8f258560d955c994c5d293860aa635adeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Mat=C4=9Bj=C4=8Dek?= Date: Tue, 13 Feb 2024 11:26:50 +0100 Subject: [PATCH] feat(MakeBodyFromResponseAction): support Content-Encoding gzip deflate --- composer.json | 1 + src/Actions/MakeBodyFromResponseAction.php | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/composer.json b/composer.json index bcc5351..7ceef13 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ ], "require": { "php": ">=8.1", + "guzzlehttp/psr7": "^2.5", "juststeveking/uri-builder": "^2.0", "php-http/discovery": "^1.14", "psr/http-client": "^1.0.1", diff --git a/src/Actions/MakeBodyFromResponseAction.php b/src/Actions/MakeBodyFromResponseAction.php index 7e26d3a..336db1f 100644 --- a/src/Actions/MakeBodyFromResponseAction.php +++ b/src/Actions/MakeBodyFromResponseAction.php @@ -4,6 +4,7 @@ namespace WrkFlow\ApiSdkBuilder\Actions; +use GuzzleHttp\Psr7\InflateStream; use JsonException; use Psr\Http\Message\ResponseInterface; use SimpleXMLElement; @@ -24,6 +25,11 @@ public function execute(string $responseClass, ResponseInterface $response): ?Ge return null; } + $encoding = strtolower($response->getHeaderLine('Content-Encoding')); + if ($encoding === 'gzip' || $encoding === 'deflate') { + $response = $response->withBody(new InflateStream($response->getBody())); + } + if (array_key_exists(BodyIsJsonInterface::class, $implements)) { return $this->convertToJson($response); }