Skip to content

Add selective GZip middleware and test - #32

Merged
D1m7asis merged 1 commit into
mainfrom
dev
Mar 17, 2026
Merged

D1m7asis merged 1 commit into
mainfrom
dev

Conversation

@D1m7asis

Copy link
Copy Markdown
Member

Introduce SelectiveGZipMiddleware that delegates to GZipMiddleware except for configured path prefixes, and replace the global GZipMiddleware registration with this selective middleware (excluding '/games/api/'). Add a test to ensure the legacy leaderboard endpoint (/games/api/leaderboard.php) is not served with gzip encoding when Accept-Encoding: gzip is present, preventing clients that can't handle gzip from receiving compressed responses.

Introduce SelectiveGZipMiddleware that delegates to GZipMiddleware except for configured path prefixes, and replace the global GZipMiddleware registration with this selective middleware (excluding '/games/api/'). Add a test to ensure the legacy leaderboard endpoint (/games/api/leaderboard.php) is not served with gzip encoding when Accept-Encoding: gzip is present, preventing clients that can't handle gzip from receiving compressed responses.
Copilot AI review requested due to automatic review settings March 17, 2026 23:15
@D1m7asis
D1m7asis merged commit 1bf59fb into main Mar 17, 2026
9 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a selective gzip compression middleware so legacy /games/api/* endpoints can opt out of response compression, and adds a regression test targeting the legacy leaderboard endpoint to avoid sending gzipped responses to clients that can’t handle them.

Changes:

  • Added SelectiveGZipMiddleware that bypasses gzip for configured path prefixes and otherwise delegates to GZipMiddleware.
  • Replaced the global GZipMiddleware registration with SelectiveGZipMiddleware, excluding '/games/api/'.
  • Added a test asserting /games/api/leaderboard.php is not served with Content-Encoding: gzip even when Accept-Encoding: gzip is provided.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
app/main.py Adds SelectiveGZipMiddleware and updates middleware registration to exclude /games/api/ from gzip.
tests/test_games_leaderboard_api.py Adds a regression test intended to ensure the legacy leaderboard endpoint is not gzipped.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +49 to +59
client = TestClient(app)

response = client.get(
'/games/api/leaderboard.php',
params={'action': 'list', 'limit': 20},
headers={'Accept-Encoding': 'gzip'},
)

assert response.status_code == 200
assert response.headers.get('content-encoding') != 'gzip'
assert response.json()['leaderboard'] == []
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.

2 participants