Skip to content

Commit

Permalink
feat(MakeBodyFromResponseAction): support Content-Encoding gzip deflate
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna authored and pionl committed Feb 13, 2024
1 parent 2edc2ad commit f3a62f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions src/Actions/MakeBodyFromResponseAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace WrkFlow\ApiSdkBuilder\Actions;

use GuzzleHttp\Psr7\InflateStream;
use JsonException;
use Psr\Http\Message\ResponseInterface;
use SimpleXMLElement;
Expand All @@ -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);
}
Expand Down

0 comments on commit f3a62f8

Please sign in to comment.