Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In order to better support streaming responses where the chunks are smaller than the file buffer size, we flush after writing. Without the explicit flush, the writes are buffered and the subsequent reads see an empty self.gzip_buffer until the file automatically flushes due to either (1) the write buffer fills, probably at 8kiB, or (2) the file is closed because the streaming response is complete. Without flushing, the GZipMiddleware doesn't work as expected for streaming responses, especially not for Server-Sent Events which are expected to be delivered immediately to clients. The code as written appears to intend to flush immediately rather than buffering, as it does immediately call `await self.send(message)`, but in practice that `message` is often empty.
- Loading branch information