Skip to content

Commit

Permalink
Merge pull request #107 from php-http/fix/remove-header-if-empty
Browse files Browse the repository at this point in the history
Remove header if there is no more encoding value
  • Loading branch information
dbu committed Jun 22, 2018
2 parents 7727489 + d65deb5 commit f6901d0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/Plugin/DecoderPluginSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/Plugin/DecoderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f6901d0

Please sign in to comment.