diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d8f46c..1ce351a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Change Log +## Unreleased + +### Deprecated + +- `DecoderPlugin` does not longer claim to support `compress` content encoding + +### Fixed + +- `DecoderPlugin` uses the right `FilteredStream` to handle `deflate` content encoding + ## 1.4.1 - 2017-02-20 ### Fixed diff --git a/spec/Plugin/DecoderPluginSpec.php b/spec/Plugin/DecoderPluginSpec.php index a4f8d7d..bff1163 100644 --- a/spec/Plugin/DecoderPluginSpec.php +++ b/spec/Plugin/DecoderPluginSpec.php @@ -28,8 +28,8 @@ function it_decodes(RequestInterface $request, ResponseInterface $response, Stre throw new SkippingException('Skipping test on hhvm, as there is no chunk encoding on hhvm'); } - $request->withHeader('TE', ['gzip', 'deflate', 'compress', 'chunked'])->shouldBeCalled()->willReturn($request); - $request->withHeader('Accept-Encoding', ['gzip', 'deflate', 'compress'])->shouldBeCalled()->willReturn($request); + $request->withHeader('TE', ['gzip', 'deflate', 'chunked'])->shouldBeCalled()->willReturn($request); + $request->withHeader('Accept-Encoding', ['gzip', 'deflate'])->shouldBeCalled()->willReturn($request); $next = function () use($response) { return new HttpFulfilledPromise($response->getWrappedObject()); }; @@ -50,8 +50,8 @@ function it_decodes(RequestInterface $request, ResponseInterface $response, Stre function it_decodes_gzip(RequestInterface $request, ResponseInterface $response, StreamInterface $stream) { - $request->withHeader('TE', ['gzip', 'deflate', 'compress', 'chunked'])->shouldBeCalled()->willReturn($request); - $request->withHeader('Accept-Encoding', ['gzip', 'deflate', 'compress'])->shouldBeCalled()->willReturn($request); + $request->withHeader('TE', ['gzip', 'deflate', 'chunked'])->shouldBeCalled()->willReturn($request); + $request->withHeader('Accept-Encoding', ['gzip', 'deflate'])->shouldBeCalled()->willReturn($request); $next = function () use($response) { return new HttpFulfilledPromise($response->getWrappedObject()); }; @@ -72,8 +72,8 @@ function it_decodes_gzip(RequestInterface $request, ResponseInterface $response, function it_decodes_deflate(RequestInterface $request, ResponseInterface $response, StreamInterface $stream) { - $request->withHeader('TE', ['gzip', 'deflate', 'compress', 'chunked'])->shouldBeCalled()->willReturn($request); - $request->withHeader('Accept-Encoding', ['gzip', 'deflate', 'compress'])->shouldBeCalled()->willReturn($request); + $request->withHeader('TE', ['gzip', 'deflate', 'chunked'])->shouldBeCalled()->willReturn($request); + $request->withHeader('Accept-Encoding', ['gzip', 'deflate'])->shouldBeCalled()->willReturn($request); $next = function () use($response) { return new HttpFulfilledPromise($response->getWrappedObject()); }; @@ -82,28 +82,6 @@ function it_decodes_deflate(RequestInterface $request, ResponseInterface $respon $response->hasHeader('Content-Encoding')->willReturn(true); $response->getHeader('Content-Encoding')->willReturn(['deflate']); $response->getBody()->willReturn($stream); - $response->withBody(Argument::type('Http\Message\Encoding\InflateStream'))->willReturn($response); - $response->withHeader('Content-Encoding', [])->willReturn($response); - - $stream->isReadable()->willReturn(true); - $stream->isWritable()->willReturn(false); - $stream->eof()->willReturn(false); - - $this->handleRequest($request, $next, function () {}); - } - - function it_decodes_inflate(RequestInterface $request, ResponseInterface $response, StreamInterface $stream) - { - $request->withHeader('TE', ['gzip', 'deflate', 'compress', 'chunked'])->shouldBeCalled()->willReturn($request); - $request->withHeader('Accept-Encoding', ['gzip', 'deflate', 'compress'])->shouldBeCalled()->willReturn($request); - $next = function () use($response) { - return new HttpFulfilledPromise($response->getWrappedObject()); - }; - - $response->hasHeader('Transfer-Encoding')->willReturn(false); - $response->hasHeader('Content-Encoding')->willReturn(true); - $response->getHeader('Content-Encoding')->willReturn(['compress']); - $response->getBody()->willReturn($stream); $response->withBody(Argument::type('Http\Message\Encoding\DecompressStream'))->willReturn($response); $response->withHeader('Content-Encoding', [])->willReturn($response); @@ -118,8 +96,8 @@ function it_does_not_decode_with_content_encoding(RequestInterface $request, Res { $this->beConstructedWith(['use_content_encoding' => false]); - $request->withHeader('TE', ['gzip', 'deflate', 'compress', 'chunked'])->shouldBeCalled()->willReturn($request); - $request->withHeader('Accept-Encoding', ['gzip', 'deflate', 'compress'])->shouldNotBeCalled(); + $request->withHeader('TE', ['gzip', 'deflate', 'chunked'])->shouldBeCalled()->willReturn($request); + $request->withHeader('Accept-Encoding', ['gzip', 'deflate'])->shouldNotBeCalled(); $next = function () use($response) { return new HttpFulfilledPromise($response->getWrappedObject()); }; diff --git a/src/Plugin/DecoderPlugin.php b/src/Plugin/DecoderPlugin.php index 0f30a7b..7666c64 100644 --- a/src/Plugin/DecoderPlugin.php +++ b/src/Plugin/DecoderPlugin.php @@ -50,7 +50,7 @@ public function __construct(array $config = []) */ public function handleRequest(RequestInterface $request, callable $next, callable $first) { - $encodings = extension_loaded('zlib') ? ['gzip', 'deflate', 'compress'] : ['identity']; + $encodings = extension_loaded('zlib') ? ['gzip', 'deflate'] : ['identity']; if ($this->useContentEncoding) { $request = $request->withHeader('Accept-Encoding', $encodings); @@ -127,12 +127,8 @@ private function decorateStream($encoding, StreamInterface $stream) return new Encoding\DechunkStream($stream); } - if (strtolower($encoding) == 'compress') { - return new Encoding\DecompressStream($stream); - } - if (strtolower($encoding) == 'deflate') { - return new Encoding\InflateStream($stream); + return new Encoding\DecompressStream($stream); } if (strtolower($encoding) == 'gzip') {