amphp / http-server

An advanced async HTTP server library for PHP, perfect for real-time apps and APIs with high concurrency demands.
https://amphp.org/http-server
MIT License
1.29k stars 100 forks source link

Duplicate data sent by compression middleware when no contentLength #341

Closed Nek- closed 1 year ago

Nek- commented 1 year ago

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:

https://github.com/amphp/http-server/blob/850f1b22ad0f3459c6ef6e89e897c8abf2b18b4c/src/Middleware/CompressionMiddleware.php#L141

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

https://github.com/amphp/http-server/blob/850f1b22ad0f3459c6ef6e89e897c8abf2b18b4c/src/Middleware/CompressionMiddleware.php#L195-L197

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).

trowski commented 1 year ago

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

Nek- commented 1 year ago

It seems to work properly with this change, yes!