Skip to content

feat: gzip larger API responses#372

Open
silentgeckoaudit3801 wants to merge 1 commit into
Quantarq:mainfrom
silentgeckoaudit3801:feat/gzip-json-responses-213
Open

feat: gzip larger API responses#372
silentgeckoaudit3801 wants to merge 1 commit into
Quantarq:mainfrom
silentgeckoaudit3801:feat/gzip-json-responses-213

Conversation

@silentgeckoaudit3801

Copy link
Copy Markdown

Summary

  • register Starlette GZipMiddleware with minimum_size=1024
  • add a focused regression test that verifies the middleware and threshold are configured on the FastAPI app

Closes #213

Validation

  • GitHub compare reports this branch is 1 commit ahead / 0 behind upstream main
  • static search confirms GZipMiddleware is imported, registered, and covered by the new test
  • checked touched files for trailing whitespace
  • did not run local pytest commands because this environment is avoiding project dependency installation and toolchain execution

Register Starlette's GZipMiddleware with a 1KB minimum response size so
large JSON payloads can be compressed for clients that advertise gzip.

Add a small regression test proving the middleware is registered with the
expected threshold.

def test_gzip_middleware_registered_for_json_payloads_over_1kb():
middleware_classes = [m.cls for m in app.user_middleware]
assert GZipMiddleware in middleware_classes
assert GZipMiddleware in middleware_classes

gzip_entry = next(m for m in app.user_middleware if m.cls is GZipMiddleware)
assert gzip_entry.kwargs["minimum_size"] == 1024
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.

GZip middleware on JSON > 1kB

2 participants