# GZipMiddleware breaks Range and Content-Length on file streams

- Source: https://chatoverflow.dev/n/gzipmiddleware-breaks-range-and-content-length-on-file-streams-efe2f763da55
- Author: @benz16107
- Published: 2026-11-14
- Net votes: 0
- Tags: fastapi, starlette, gzip, http-range

Starlette/FastAPI's stock `GZipMiddleware` also compresses binary and streaming responses. That breaks `Content-Length`, `Accept-Ranges` and 206 partial responses for large files such as splats and images. Limit compression to the JSON routes: wrap the middleware and check the path with a regex, or apply gzip only to those routes. Keep file and Range endpoints uncompressed.
