Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 28, 2025

The is_gzipped variable in _inject_toolbar() was ambiguous—it initially tracked whether the Content-Encoding header indicated gzip, then was repurposed to track decompression success.

Changes

  • Renamed is_gzipped to decompressed with explicit success tracking
  • Set flag only when gzip.decompress() succeeds, not based on header presence
  • Replaced conditional assignment (is_gzipped = False) with explicit initialization pattern

Before:

is_gzipped = content_encoding.lower() == "gzip"
if is_gzipped:
    try:
        body = gzip.decompress(body)
    except (gzip.BadGzipFile, OSError):
        is_gzipped = False  # Repurposed to mean "decompression succeeded"

After:

decompressed = False
if content_encoding.lower() == "gzip":
    try:
        body = gzip.decompress(body)
        decompressed = True  # Explicit success tracking
    except (gzip.BadGzipFile, OSError):
        pass

The flag now unambiguously indicates whether we hold decompressed data, making the subsequent error handling logic clearer.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

The `is_gzipped` variable was ambiguous - it initially tracked whether
the header indicated gzip encoding, but then was repurposed to track
whether decompression succeeded. This made the code harder to understand.

Renamed to `decompressed` to explicitly indicate it tracks whether we
successfully decompressed the body. This makes the logic clearer:
- If decompression succeeds and UTF-8 decoding fails, return the
  decompressed body with no content-encoding header
- If decompression fails and UTF-8 decoding fails, return the original
  body with the original content-encoding header

Addresses feedback: #24 (comment)

Co-authored-by: JacobCoffee <45884264+JacobCoffee@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 28, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: /usr/bin/curl curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Update gzip-compressed responses in toolbar injection Refactor gzip decompression flag to explicitly track success state Dec 28, 2025
Copilot AI requested a review from JacobCoffee December 28, 2025 03:30
@JacobCoffee JacobCoffee marked this pull request as ready for review December 28, 2025 03:36
@JacobCoffee JacobCoffee merged commit 499dd68 into fix/gzip-compression-injection Dec 28, 2025
@JacobCoffee JacobCoffee deleted the copilot/sub-pr-24-yet-again branch December 28, 2025 03:36
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