Conversation
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.
There was a problem hiding this comment.
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
SelectiveGZipMiddlewarethat bypasses gzip for configured path prefixes and otherwise delegates toGZipMiddleware. - Replaced the global
GZipMiddlewareregistration withSelectiveGZipMiddleware, excluding'/games/api/'. - Added a test asserting
/games/api/leaderboard.phpis not served withContent-Encoding: gzipeven whenAccept-Encoding: gzipis 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'] == [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.