Fix #93: Fix incorrect Content-Length headers causing truncated responses and timeouts #122

Open
typosaurus wants to merge 2 commits from typosaurus/ticket-93 into master
Collaborator

Resolves #93.

Plan

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:

    app.add_middleware(GZipMiddleware, minimum_size=1000)
    
  2. /workspace/repo/main.py (top of file)
    Remove the corresponding import:

    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.

Opened automatically by Typosaurus.

Resolves #93. ## Plan ## 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. Opened automatically by Typosaurus.
typosaurus added 2 commits 2026-07-23 04:06:46 +02:00
ticket #93 attempt 1
Some checks failed
DevPlace CI / test (pull_request) Failing after 11s
63366bb240
typosaurus force-pushed typosaurus/ticket-93 from feb1963aad to 63366bb240 2026-07-23 04:06:47 +02:00 Compare
Some checks failed
DevPlace CI / test (pull_request) Failing after 11s
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin typosaurus/ticket-93:typosaurus/ticket-93
git checkout typosaurus/ticket-93
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: retoor/devplacepy#122
No description provided.