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 101 forks source link

Use timeouts to avoid long buffering in CompressionMiddleware #334

Closed trowski closed 2 years ago

trowski commented 2 years ago

This addresses #324 by using an adjustable timeout (100ms by default) when checking the body size to determine if the body should be compressed or when buffering chunks while sending the body. When the timeout expires, any buffered data is sent, regardless of if it meets the minimum chunk size.

For v3, the minimum chunk size param has been removed as such functionality is better within a stream implementation instead of being handled by the middleware. Cancellations also keep the implementation simpler. An untagged commit in byte-stream is required, https://github.com/amphp/byte-stream/commit/092e9316f8b24edd620a1515ee01e487080f16ad. See https://github.com/amphp/http-server/commit/879a0f36504d348846956c08fe1416c338a77262 for the v3 implementation.

kelunik commented 2 years ago

The v3 implementation also LGTM.