Skip to content

Commit a131287

Browse files
committed
Fix gzip with nyholm stream
1 parent d0daaac commit a131287

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Actions/MakeBodyFromResponseAction.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use GuzzleHttp\Psr7\InflateStream;
88
use JsonException;
9+
use Nyholm\Psr7\Stream;
910
use Psr\Http\Message\ResponseInterface;
1011
use SimpleXMLElement;
1112
use WrkFlow\ApiSdkBuilder\Exceptions\InvalidJsonResponseException;
@@ -27,9 +28,13 @@ public function execute(string $responseClass, ResponseInterface $response): ?Ge
2728

2829
$encoding = strtolower($response->getHeaderLine('Content-Encoding'));
2930
if ($encoding === 'gzip' || $encoding === 'deflate') {
30-
$response = $response
31-
->withBody(new InflateStream($response->getBody()))
32-
->withoutHeader('Content-Encoding');
31+
$stream = $response->getBody();
32+
// Nyholm auto implements the stream with gzip/deflate
33+
if (! ($stream instanceof Stream)) {
34+
$response = $response
35+
->withBody(new InflateStream($response->getBody()))
36+
->withoutHeader('Content-Encoding');
37+
}
3338
}
3439

3540
if (array_key_exists(BodyIsJsonInterface::class, $implements)) {

0 commit comments

Comments
 (0)