Fix GZipMiddleware buffering streaming response chunks

Closed
JA
7mo ago
+22-0

Summary

GZipResponder.apply_compression() never called gzip_file.flush() for intermediate streaming chunks (more_body=True), causing zlib to hold compressed bytes in its internal buffer until ~32KB accumulated or the stream closed. Added self.gzip_file.flush() (Z_SYNC_FLUSH) so compressed bytes are emitted immediately for each chunk.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.