Changes between Initial Version and Version 1 of Ticket #36655


Ignore:
Timestamp:
Oct 10, 2025, 11:10:54 AM (11 hours ago)
Author:
Adam Johnson
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #36655

    • Property Summary GzipMiddleware buffers streaming responsesGZipMiddleware buffers streaming responses
  • Ticket #36655 – Description

    initial v1  
    1 Currently, `GzipMiddleware`, via `compress_sequence()`, buffers the entire response before sending it to the client. This can cause issues for clients that expect to receive data in chunks, such as those using Server-Sent Events (SSE) or WebSockets.
     1Currently, `GZipMiddleware`, via `compress_sequence()`, buffers the entire response before sending it to the client. This can cause issues for clients that expect to receive data in chunks, such as those using Server-Sent Events (SSE) or WebSockets.
    22
    33This issue was reported to me in the django-browser-reload project back in [https://github.com/adamchainz/django-browser-reload/pull/161 Issue #161 (2023)], where a contributor fixed it with a workaround, and I didn't think to investigate. Now, while implementing [https://github.com/adamchainz/django-http-compression django-http-compression], I have realized that it’s a proper bug that can be fixed by adding a call to `zfile.flush()`, as done in its [https://github.com/adamchainz/django-http-compression/pull/8 PR #8].
    44
    5 To reproduce the issue, use the below app, which can be run with `uv run --script`. If you comment out `GzipMiddleware` and load the page in a browser, you will see the numbers incrementing every second. If you include `GzipMiddleware`, the page will never load. Adding the `zfile.flush()` call in `compress_sequence()` fixes the issue.
     5To reproduce the issue, use the app below, which can be run with `uv run --script`. If you comment out `GzipMiddleware` and load the page in a browser, you will see the numbers incrementing every second. If you include `GzipMiddleware`, the page will never load. Adding the `zfile.flush()` call in `compress_sequence()` fixes the issue.
    66
    77{{{#!python
Back to Top