Skip to content

Commit f6901d0

Browse files
authored
Merge pull request #107 from php-http/fix/remove-header-if-empty
Remove header if there is no more encoding value
2 parents 7727489 + d65deb5 commit f6901d0

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
- 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
1212

13+
### Fixed
14+
15+
- Decoder plugin will now remove header when there is no more encoding, instead of setting to an empty array
16+
1317
## 1.7.0 - 2017-11-30
1418

1519
### Added

spec/Plugin/DecoderPluginSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function it_decodes(RequestInterface $request, ResponseInterface $response, Stre
3838
$response->getHeader('Transfer-Encoding')->willReturn(['chunked']);
3939
$response->getBody()->willReturn($stream);
4040
$response->withBody(Argument::type('Http\Message\Encoding\DechunkStream'))->willReturn($response);
41-
$response->withHeader('Transfer-Encoding', [])->willReturn($response);
41+
$response->withoutHeader('Transfer-Encoding')->willReturn($response);
4242
$response->hasHeader('Content-Encoding')->willReturn(false);
4343

4444
$stream->isReadable()->willReturn(true);
@@ -61,7 +61,7 @@ function it_decodes_gzip(RequestInterface $request, ResponseInterface $response,
6161
$response->getHeader('Content-Encoding')->willReturn(['gzip']);
6262
$response->getBody()->willReturn($stream);
6363
$response->withBody(Argument::type('Http\Message\Encoding\GzipDecodeStream'))->willReturn($response);
64-
$response->withHeader('Content-Encoding', [])->willReturn($response);
64+
$response->withoutHeader('Content-Encoding')->willReturn($response);
6565

6666
$stream->isReadable()->willReturn(true);
6767
$stream->isWritable()->willReturn(false);
@@ -83,7 +83,7 @@ function it_decodes_deflate(RequestInterface $request, ResponseInterface $respon
8383
$response->getHeader('Content-Encoding')->willReturn(['deflate']);
8484
$response->getBody()->willReturn($stream);
8585
$response->withBody(Argument::type('Http\Message\Encoding\DecompressStream'))->willReturn($response);
86-
$response->withHeader('Content-Encoding', [])->willReturn($response);
86+
$response->withoutHeader('Content-Encoding')->willReturn($response);
8787

8888
$stream->isReadable()->willReturn(true);
8989
$stream->isWritable()->willReturn(false);

src/Plugin/DecoderPlugin.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ private function decodeOnEncodingHeader($headerName, ResponseInterface $response
107107
$response = $response->withBody($stream);
108108
}
109109

110-
$response = $response->withHeader($headerName, $newEncodings);
110+
if (\count($newEncodings) > 0) {
111+
$response = $response->withHeader($headerName, $newEncodings);
112+
} else {
113+
$response = $response->withoutHeader($headerName);
114+
}
111115
}
112116

113117
return $response;

0 commit comments

Comments
 (0)