Skip to content

Remove header if there is no more encoding value #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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