fix: add max_length support to Gzip/Brotli decoders for urllib3 v2.6+ compatibility#492
fix: add max_length support to Gzip/Brotli decoders for urllib3 v2.6+ compatibility#492benijaichenco wants to merge 2 commits intogoogleapis:mainfrom
Conversation
|
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. |
3d7a3b2 to
0b38722
Compare
|
thanks @benijaichenco for contributing :) |
|
All set @chandra-siri :) |
|
Thank you for contributing! We are missing test coverage for lines 692 and 743, do you think that is something you could add @benijaichenco? |
|
Also the linter is failing
|
| @property | ||
| def has_unconsumed_tail(self) -> bool: | ||
| # Checks for buffered, unread bytes | ||
| return self._decoder.has_unconsumed_tail |
There was a problem hiding this comment.
this property is not required for _GzipDecoder . It's needed only for _BrotliDecoder.
Please remove these lines.
|
It'd also be good to add an explicit test against the latest |
|
any progress on this? (I'm mostly just wanting remove our monkeypatch code) |
|
Closing. Superceded by #495. |
…495) ## 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](https://github.com/urllib3/urllib3/blob/bfe8e198a13800e3ee8ef8124a8928acb170c843/src/urllib3/response.py#L55), 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 - [x] `pytest tests/unit/requests/test_download.py` — all pass - [x] `pytest tests_async/unit/requests/test_download.py` — all pass - [x] Full unit suite (514 tests) — all pass - [x] No lint issues (flake8 clean) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Chalmer Lowe <chalmerlowe@google.com>
|
Closing. Superceded by #495. |
…495) ## 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](https://github.com/urllib3/urllib3/blob/bfe8e198a13800e3ee8ef8124a8928acb170c843/src/urllib3/response.py#L55), 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 - [x] `pytest tests/unit/requests/test_download.py` — all pass - [x] `pytest tests_async/unit/requests/test_download.py` — all pass - [x] Full unit suite (514 tests) — all pass - [x] No lint issues (flake8 clean) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Chalmer Lowe <chalmerlowe@google.com>
Fixes #491
Adds the required
max_length=Noneparameter to decoder methods to maintain compatibility withurllib3 >= 2.6.0.