Skip to content

fix: add max_length support to Gzip/Brotli decoders for urllib3 2.6+#495

Open
CalNightingale wants to merge 1 commit intogoogleapis:mainfrom
CalNightingale:fix/urllib3-2.6-decoder-compat
Open

fix: add max_length support to Gzip/Brotli decoders for urllib3 2.6+#495
CalNightingale wants to merge 1 commit intogoogleapis:mainfrom
CalNightingale:fix/urllib3-2.6-decoder-compat

Conversation

@CalNightingale
Copy link

Summary

Fixes #491. Supersedes #492 (stale).

urllib3 >= 2.6.0 now passes max_length to decoder.decompress() and accesses decoder.has_unconsumed_tail. Our custom _GzipDecoder and _BrotliDecoder wrappers didn't accept these, causing TypeError at runtime.

This PR:

  • Updates _GzipDecoder.decompress and _BrotliDecoder.decompress to accept and forward max_length, with a TypeError fallback for older urllib3
  • Adds has_unconsumed_tail property to _BrotliDecoder (the proxy class that needs it explicitly)
  • Applies the same fix to the async _GzipDecoder in google/_async_resumable_media/
  • Adds test coverage for the new max_length forwarding, the fallback path, and has_unconsumed_tail

Feedback from #492 addressed

  • max_length=-1 default (chandra-siri) — uses -1 to match urllib3's default, not None
  • has_unconsumed_tail only on _BrotliDecoder (chandra-siri) — _GzipDecoder inherits this from the parent urllib3.response.GzipDecoder, so no override is needed
  • Lint failure (BrennaEpp) — no trailing whitespace
  • Missing test coverage for fallback paths (BrennaEpp) — added tests for max_length forwarding, TypeError fallback, and has_unconsumed_tail (with AttributeError fallback for older urllib3)

Test plan

  • pytest tests/unit/requests/test_download.py — all pass
  • pytest tests_async/unit/requests/test_download.py — all pass
  • Full unit suite (514 tests) — all pass
  • No lint issues (flake8 clean)

🤖 Generated with Claude Code

@google-cla
Copy link

google-cla bot commented Jan 28, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: storage Issues related to the googleapis/google-resumable-media-python API. labels Jan 28, 2026
…compatibility

urllib3 2.6+ passes max_length to decoder.decompress(). Update
_GzipDecoder and _BrotliDecoder to accept and forward max_length,
with a TypeError fallback for older urllib3. Add has_unconsumed_tail
property to _BrotliDecoder (the proxy class that needs it; _GzipDecoder
inherits it from the parent).

Fixes googleapis#491
@CalNightingale CalNightingale force-pushed the fix/urllib3-2.6-decoder-compat branch from 11c51a5 to 2aa67b2 Compare January 28, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the googleapis/google-resumable-media-python API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_GzipDecoder.decompress() TypeError: unexpected keyword argument 'max_length'

2 participants