amphp / http-server

An advanced async HTTP server library for PHP, perfect for real-time apps and APIs with high concurrency demands.

Home Page:https://amphp.org/http-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duplicate data sent by compression middleware when no contentLength

Nek- opened this issue · comments

I found an issue in the CompressionMiddleware in the case of streaming a response with no content length.

The following line is filling the $bodyBuffer variable:

$bodyBuffer .= $chunk = yield Promise\timeout($promise, \max(1, $expiration - Loop::now()));

While it's also done some lines after... Without cleaning the original var.

$bodyBuffer .= $chunk = yield $bodyBuffer === ''
? $promise
: Promise\timeout($promise, \max(1, $expiration - Loop::now()));

I don't understand why it's done this way so I'm not sure I can provide a fix (something tells me it's not just stupid but has a purpose that I don't understand).

Does adding $promise = $body->read() on line 144 fix the issue?

It seems to work properly with this change, yes!