Closed Nek- closed 2 years ago
Sorry for the delay in responding – though it was clear you figured this out quickly, probably why none of us felt the need.
CompressionMiddleware
buffers a certain number of bytes before compressing them to be more efficient. I wonder if using compression with SSE is wise. You may actually use more data for small payloads. If you are sending larger payloads on average, then reducing the number of bytes buffered in the constructor is exactly the solution you needed.
The best solution would actually be to buffer only the message. I think the current behavior is far from optimal.
FYI I was looking into that because I was trying to build a mercure.rock implementation on my own.
I missed the obvious here and @kelunik pointed it out in chat. I guess we should change the behavior of CompressionMiddleware
for text/event-stream
rather than forcing users to disable compression for certain routes.
We also have the stream threshold setting that gets in the way of event streaming. Looks like it would be advantageous to add an event-stream example too.
In the merged change, bufferTimeout is a constructor parameter for CompressionMiddleware, but the property is not set in the constructor. This leads to bufferTimout always being null.
I have prepared the (single-line change) in a PR here: https://github.com/amphp/http-server/pull/339
I tried to make a super-simple SSE server (code below). It was just not working until I disabled the compression. Since I assume streamed responses should work with compression enabled, I open an issue about it.
Using this works: