Skip to content

Support gzip-compressed HTTP responses - #159

Merged
diazona merged 1 commit into
pytest-dev:mainfrom
TOMASEZARATE:gzip-responses
Nov 27, 2026
Merged

diazona merged 1 commit into
pytest-dev:mainfrom
TOMASEZARATE:gzip-responses

Conversation

@TOMASEZARATE

@TOMASEZARATE TOMASEZARATE commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #27

The HTTP server already had a compress attribute and a FIXME to gzip the response body, but that code was never finished.

There's now a Compression enum in pytest_localserver.http (currently just Compression.GZIP), and serve_content() accepts compress=Compression.GZIP. You can also set httpserver.compress the same way. When the request's Accept-Encoding header allows gzip, the body is compressed and sent with Content-Encoding: gzip and the correct Content-Length. Compression stays off by default, so existing tests are unchanged.

I used an AI assistant (Cursor Agent with Grok 4.7) while writing this change. I reviewed the code myself, and the commits carry Assisted-by trailers.

@diazona diazona left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, thanks for the contribution! I had just a few minor suggestions.

Also, assuming nobody objects to the proposed LLM policy in #161, just make sure to add the appropriate disclosure (Assisted-by in the commit and some sort of mention in the PR description).

Comment thread pytest_localserver/http.py Resolved
Comment thread pytest_localserver/http.py Resolved
Comment thread CHANGES Resolved
@cursor
cursor Bot force-pushed the gzip-responses branch from cc30e88 to 5fa1d13 Compare November 23, 2026 10:54
@TOMASEZARATE

Copy link
Copy Markdown
Contributor Author

Thanks for the review @diazona. I pushed a new commit with the changes:

  • the chunked logic is now a plain if/elif/else
  • compress takes a Compression enum (just GZIP for now) or None, so it no longer accepts bools or strings
  • removed the CHANGES entry

I also updated the PR description to mention the AI assistance, and both commits have an Assisted-by trailer.

@diazona diazona left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! I'm good to proceed with this now. Sorry it took me a few days to get back to this.

@diazona

diazona commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Oh, actually one more thing, would you mind squashing commits? It's not really a big deal, but we like the commit history to be broken down in a useful way even after merging, and "Address review feedback" isn't really a useful commit to have on its own.

serve_content() now accepts compress=Compression.GZIP, matching the
old unfinished compress attribute. The body is gzipped and sent with
Content-Encoding: gzip and the correct Content-Length, but only when
the request's Accept-Encoding header allows it.

Assisted-by: Cursor Agent with Grok 4.7
@cursor
cursor Bot force-pushed the gzip-responses branch from 953f6d6 to 7dbc028 Compare November 26, 2026 10:41
@TOMASEZARATE

Copy link
Copy Markdown
Contributor Author

Squashed into a single commit, thanks for the review!

@diazona
diazona enabled auto-merge November 27, 2026 01:07
@diazona
diazona merged commit 1daba2d into pytest-dev:main Nov 27, 2026
17 checks passed
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.

Support compressed responses

2 participants