Skip to content

Commit f3a62f8

Browse files
h4kunapionl
authored andcommitted
feat(MakeBodyFromResponseAction): support Content-Encoding gzip deflate
1 parent 2edc2ad commit f3a62f8

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
],
1313
"require": {
1414
"php": ">=8.1",
15+
"guzzlehttp/psr7": "^2.5",
1516
"juststeveking/uri-builder": "^2.0",
1617
"php-http/discovery": "^1.14",
1718
"psr/http-client": "^1.0.1",

src/Actions/MakeBodyFromResponseAction.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace WrkFlow\ApiSdkBuilder\Actions;
66

7+
use GuzzleHttp\Psr7\InflateStream;
78
use JsonException;
89
use Psr\Http\Message\ResponseInterface;
910
use SimpleXMLElement;
@@ -24,6 +25,11 @@ public function execute(string $responseClass, ResponseInterface $response): ?Ge
2425
return null;
2526
}
2627

28+
$encoding = strtolower($response->getHeaderLine('Content-Encoding'));
29+
if ($encoding === 'gzip' || $encoding === 'deflate') {
30+
$response = $response->withBody(new InflateStream($response->getBody()));
31+
}
32+
2733
if (array_key_exists(BodyIsJsonInterface::class, $implements)) {
2834
return $this->convertToJson($response);
2935
}

0 commit comments

Comments
 (0)