Skip to content

Commit 913b7eb

Browse files
ajgarlagsagikazarmark
authored andcommitted
Fix deflate encoding handling and disable compress encoding (#61)
1 parent 6027a1d commit 913b7eb

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change Log
22

3+
## Unreleased
4+
5+
### Deprecated
6+
7+
- `DecoderPlugin` does not longer claim to support `compress` content encoding
8+
9+
### Fixed
10+
11+
- `DecoderPlugin` uses the right `FilteredStream` to handle `deflate` content encoding
12+
313
## 1.4.1 - 2017-02-20
414

515
### Fixed

spec/Plugin/DecoderPluginSpec.php

+8-30
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ function it_decodes(RequestInterface $request, ResponseInterface $response, Stre
2828
throw new SkippingException('Skipping test on hhvm, as there is no chunk encoding on hhvm');
2929
}
3030

31-
$request->withHeader('TE', ['gzip', 'deflate', 'compress', 'chunked'])->shouldBeCalled()->willReturn($request);
32-
$request->withHeader('Accept-Encoding', ['gzip', 'deflate', 'compress'])->shouldBeCalled()->willReturn($request);
31+
$request->withHeader('TE', ['gzip', 'deflate', 'chunked'])->shouldBeCalled()->willReturn($request);
32+
$request->withHeader('Accept-Encoding', ['gzip', 'deflate'])->shouldBeCalled()->willReturn($request);
3333
$next = function () use($response) {
3434
return new HttpFulfilledPromise($response->getWrappedObject());
3535
};
@@ -50,8 +50,8 @@ function it_decodes(RequestInterface $request, ResponseInterface $response, Stre
5050

5151
function it_decodes_gzip(RequestInterface $request, ResponseInterface $response, StreamInterface $stream)
5252
{
53-
$request->withHeader('TE', ['gzip', 'deflate', 'compress', 'chunked'])->shouldBeCalled()->willReturn($request);
54-
$request->withHeader('Accept-Encoding', ['gzip', 'deflate', 'compress'])->shouldBeCalled()->willReturn($request);
53+
$request->withHeader('TE', ['gzip', 'deflate', 'chunked'])->shouldBeCalled()->willReturn($request);
54+
$request->withHeader('Accept-Encoding', ['gzip', 'deflate'])->shouldBeCalled()->willReturn($request);
5555
$next = function () use($response) {
5656
return new HttpFulfilledPromise($response->getWrappedObject());
5757
};
@@ -72,8 +72,8 @@ function it_decodes_gzip(RequestInterface $request, ResponseInterface $response,
7272

7373
function it_decodes_deflate(RequestInterface $request, ResponseInterface $response, StreamInterface $stream)
7474
{
75-
$request->withHeader('TE', ['gzip', 'deflate', 'compress', 'chunked'])->shouldBeCalled()->willReturn($request);
76-
$request->withHeader('Accept-Encoding', ['gzip', 'deflate', 'compress'])->shouldBeCalled()->willReturn($request);
75+
$request->withHeader('TE', ['gzip', 'deflate', 'chunked'])->shouldBeCalled()->willReturn($request);
76+
$request->withHeader('Accept-Encoding', ['gzip', 'deflate'])->shouldBeCalled()->willReturn($request);
7777
$next = function () use($response) {
7878
return new HttpFulfilledPromise($response->getWrappedObject());
7979
};
@@ -82,28 +82,6 @@ function it_decodes_deflate(RequestInterface $request, ResponseInterface $respon
8282
$response->hasHeader('Content-Encoding')->willReturn(true);
8383
$response->getHeader('Content-Encoding')->willReturn(['deflate']);
8484
$response->getBody()->willReturn($stream);
85-
$response->withBody(Argument::type('Http\Message\Encoding\InflateStream'))->willReturn($response);
86-
$response->withHeader('Content-Encoding', [])->willReturn($response);
87-
88-
$stream->isReadable()->willReturn(true);
89-
$stream->isWritable()->willReturn(false);
90-
$stream->eof()->willReturn(false);
91-
92-
$this->handleRequest($request, $next, function () {});
93-
}
94-
95-
function it_decodes_inflate(RequestInterface $request, ResponseInterface $response, StreamInterface $stream)
96-
{
97-
$request->withHeader('TE', ['gzip', 'deflate', 'compress', 'chunked'])->shouldBeCalled()->willReturn($request);
98-
$request->withHeader('Accept-Encoding', ['gzip', 'deflate', 'compress'])->shouldBeCalled()->willReturn($request);
99-
$next = function () use($response) {
100-
return new HttpFulfilledPromise($response->getWrappedObject());
101-
};
102-
103-
$response->hasHeader('Transfer-Encoding')->willReturn(false);
104-
$response->hasHeader('Content-Encoding')->willReturn(true);
105-
$response->getHeader('Content-Encoding')->willReturn(['compress']);
106-
$response->getBody()->willReturn($stream);
10785
$response->withBody(Argument::type('Http\Message\Encoding\DecompressStream'))->willReturn($response);
10886
$response->withHeader('Content-Encoding', [])->willReturn($response);
10987

@@ -118,8 +96,8 @@ function it_does_not_decode_with_content_encoding(RequestInterface $request, Res
11896
{
11997
$this->beConstructedWith(['use_content_encoding' => false]);
12098

121-
$request->withHeader('TE', ['gzip', 'deflate', 'compress', 'chunked'])->shouldBeCalled()->willReturn($request);
122-
$request->withHeader('Accept-Encoding', ['gzip', 'deflate', 'compress'])->shouldNotBeCalled();
99+
$request->withHeader('TE', ['gzip', 'deflate', 'chunked'])->shouldBeCalled()->willReturn($request);
100+
$request->withHeader('Accept-Encoding', ['gzip', 'deflate'])->shouldNotBeCalled();
123101
$next = function () use($response) {
124102
return new HttpFulfilledPromise($response->getWrappedObject());
125103
};

src/Plugin/DecoderPlugin.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(array $config = [])
5050
*/
5151
public function handleRequest(RequestInterface $request, callable $next, callable $first)
5252
{
53-
$encodings = extension_loaded('zlib') ? ['gzip', 'deflate', 'compress'] : ['identity'];
53+
$encodings = extension_loaded('zlib') ? ['gzip', 'deflate'] : ['identity'];
5454

5555
if ($this->useContentEncoding) {
5656
$request = $request->withHeader('Accept-Encoding', $encodings);
@@ -127,12 +127,8 @@ private function decorateStream($encoding, StreamInterface $stream)
127127
return new Encoding\DechunkStream($stream);
128128
}
129129

130-
if (strtolower($encoding) == 'compress') {
131-
return new Encoding\DecompressStream($stream);
132-
}
133-
134130
if (strtolower($encoding) == 'deflate') {
135-
return new Encoding\InflateStream($stream);
131+
return new Encoding\DecompressStream($stream);
136132
}
137133

138134
if (strtolower($encoding) == 'gzip') {

0 commit comments

Comments
 (0)