## Implementation Plan **Root cause identified**: Double compression – nginx (`gzip on`, `gzip_proxied any`) re-compresses the already-compressed response from Python’s `GZipMiddleware`, leading to metadata corruption and the reported Content-Length mismatch. **Fix**: Remove `GZipMiddleware` from the Python application. nginx (which is always deployed in production) already handles compression correctly for all proxy responses. This eliminates the double-compression anti-pattern without losing compression at the edge. ### Changes to make 1. **`/workspace/repo/main.py`** (line approximately 614) Remove the middleware registration line: ```python app.add_middleware(GZipMiddleware, minimum_size=1000) ``` 2. **`/workspace/repo/main.py`** (top of file) Remove the corresponding import: ```python from starlette.middleware.gzip import GZipMiddleware ``` If this import is used elsewhere (unlikely), leave it; otherwise delete it. 3. **No other files need modification**. - nginx configuration (`nginx/nginx.conf.template`) remains unchanged – `gzip on` already covers all response types. - Tests do not cover Content-Length or GZip behaviour, and removal will not break any existing test. ### Verifying correctness - The application will serve uncompressed responses in development (no nginx). This is acceptable and standard behaviour. - In production, nginx adds compression correctly without double-compressing. - The test suite must pass, and no new lint violations may be introduced. ### Execution steps 1. Open `main.py`. 2. Comment or remove the `from starlette.middleware.gzip import GZipMiddleware` line. 3. Comment or remove the `app.add_middleware(GZipMiddleware, minimum_size=1000)` line. 4. Run `pip install -e '.[dev]' -q` to ensure dependencies are installed. 5. Run `python -m pytest` to confirm all tests pass. 6. Run the project’s linter (e.g., `ruff check .` or equivalent) to confirm no new violations. --- ## Definition of Done - [ ] `GZipMiddleware` import and middleware registration are removed from `main.py`. - [ ] The project’s test command completes with zero failures: `pip install -e '.[dev]' -q && python -m pytest` - [ ] No new lint violations are introduced (lint command passes cleanly). - [ ] The server no longer sends `Content-Encoding: gzip` when running without nginx; production nginx continues to compress responses correctly.