Skip to content

Conversation

@shreyas-dev
Copy link

Summary

This PR refactors the GZipMiddleware to make excluded content types configurable via a constructor parameter instead of using a hardcoded constant.

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.

@shreyas-dev shreyas-dev force-pushed the main branch 2 times, most recently from 2bb9a61 to fd68214 Compare October 15, 2025 10:25
@Kludex
Copy link
Owner

Kludex commented Oct 18, 2025

What is the issue you are having?

@petoknm
Copy link

petoknm commented Nov 4, 2025

The DEFAULT_EXCLUDED_CONTENT_TYPES variable is sometimes not what users want. In my case, I want event-stream to be compressed because I'm using data-star and returning a lot of very compressible html.

A workaround I've been using for now has been to either edit the variable directly in the package in my virtual enviroment or:

from fastapi.middleware.gzip import GZipMiddleware
from starlette.middleware import gzip

app = FastAPI()
app.add_middleware(GZipMiddleware, minimum_size=1000, compresslevel=5)
gzip.DEFAULT_EXCLUDED_CONTENT_TYPES = ()

which is not pretty IMO... would like this to be configurable the same way minimum_size and compresslevel are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants