diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c31194..f1ba752 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ - AddPathPlugin no longer add prefix multiple times if a request is restarted - it now only adds the prefix if that request chain has not yet passed through the AddPathPlugin +### Fixed + +- Decoder plugin will now remove header when there is no more encoding, instead of setting to an empty array + ## 1.7.0 - 2017-11-30 ### Added diff --git a/spec/Plugin/DecoderPluginSpec.php b/spec/Plugin/DecoderPluginSpec.php index bff1163..7543027 100644 --- a/spec/Plugin/DecoderPluginSpec.php +++ b/spec/Plugin/DecoderPluginSpec.php @@ -38,7 +38,7 @@ function it_decodes(RequestInterface $request, ResponseInterface $response, Stre $response->getHeader('Transfer-Encoding')->willReturn(['chunked']); $response->getBody()->willReturn($stream); $response->withBody(Argument::type('Http\Message\Encoding\DechunkStream'))->willReturn($response); - $response->withHeader('Transfer-Encoding', [])->willReturn($response); + $response->withoutHeader('Transfer-Encoding')->willReturn($response); $response->hasHeader('Content-Encoding')->willReturn(false); $stream->isReadable()->willReturn(true); @@ -61,7 +61,7 @@ function it_decodes_gzip(RequestInterface $request, ResponseInterface $response, $response->getHeader('Content-Encoding')->willReturn(['gzip']); $response->getBody()->willReturn($stream); $response->withBody(Argument::type('Http\Message\Encoding\GzipDecodeStream'))->willReturn($response); - $response->withHeader('Content-Encoding', [])->willReturn($response); + $response->withoutHeader('Content-Encoding')->willReturn($response); $stream->isReadable()->willReturn(true); $stream->isWritable()->willReturn(false); @@ -83,7 +83,7 @@ function it_decodes_deflate(RequestInterface $request, ResponseInterface $respon $response->getHeader('Content-Encoding')->willReturn(['deflate']); $response->getBody()->willReturn($stream); $response->withBody(Argument::type('Http\Message\Encoding\DecompressStream'))->willReturn($response); - $response->withHeader('Content-Encoding', [])->willReturn($response); + $response->withoutHeader('Content-Encoding')->willReturn($response); $stream->isReadable()->willReturn(true); $stream->isWritable()->willReturn(false); diff --git a/src/Plugin/DecoderPlugin.php b/src/Plugin/DecoderPlugin.php index b661b61..0239d40 100644 --- a/src/Plugin/DecoderPlugin.php +++ b/src/Plugin/DecoderPlugin.php @@ -107,7 +107,11 @@ private function decodeOnEncodingHeader($headerName, ResponseInterface $response $response = $response->withBody($stream); } - $response = $response->withHeader($headerName, $newEncodings); + if (\count($newEncodings) > 0) { + $response = $response->withHeader($headerName, $newEncodings); + } else { + $response = $response->withoutHeader($headerName); + } } return $response;