Commit cb90060
fix: add max_length support to Gzip/Brotli decoders for urllib3 2.6+ (#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>1 parent 1bfd9a7 commit cb90060Copy full SHA for cb90060
4 files changed
+113-6Lines changed: 113 additions & 6 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- packages/google-resumable-media
- google
- _async_resumable_media/requests
- resumable_media/requests
- tests_async/unit/requests
- tests/unit/requests
Expand file treeCollapse file tree
Open diff view settings
Collapse file
packages/google-resumable-media/google/_async_resumable_media/requests/download.py
Copy file name to clipboardExpand all lines: packages/google-resumable-media/google/_async_resumable_media/requests/download.py+7-2Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
452 | 452 | |
453 | 453 | |
454 | 454 | |
455 | | - |
| 455 | + |
456 | 456 | |
457 | 457 | |
458 | 458 | |
459 | 459 | |
| 460 | + |
| 461 | + |
460 | 462 | |
461 | 463 | |
462 | 464 | |
463 | 465 | |
464 | 466 | |
465 | | - |
| 467 | + |
| 468 | + |
| 469 | + |
| 470 | + |
Collapse file
packages/google-resumable-media/google/resumable_media/requests/download.py
Copy file name to clipboardExpand all lines: packages/google-resumable-media/google/resumable_media/requests/download.py+21-4Lines changed: 21 additions & 4 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
667 | 667 | |
668 | 668 | |
669 | 669 | |
670 | | - |
| 670 | + |
671 | 671 | |
672 | 672 | |
673 | 673 | |
674 | 674 | |
| 675 | + |
| 676 | + |
675 | 677 | |
676 | 678 | |
677 | 679 | |
678 | 680 | |
679 | 681 | |
680 | | - |
| 682 | + |
| 683 | + |
| 684 | + |
| 685 | + |
681 | 686 | |
682 | 687 | |
683 | 688 | |
| ||
703 | 708 | |
704 | 709 | |
705 | 710 | |
706 | | - |
| 711 | + |
707 | 712 | |
708 | 713 | |
709 | 714 | |
710 | 715 | |
| 716 | + |
| 717 | + |
711 | 718 | |
712 | 719 | |
713 | 720 | |
714 | 721 | |
715 | 722 | |
716 | | - |
| 723 | + |
| 724 | + |
| 725 | + |
| 726 | + |
| 727 | + |
| 728 | + |
| 729 | + |
| 730 | + |
| 731 | + |
| 732 | + |
| 733 | + |
717 | 734 | |
718 | 735 | |
719 | 736 | |
|
Collapse file
packages/google-resumable-media/tests/unit/requests/test_download.py
Copy file name to clipboardExpand all lines: packages/google-resumable-media/tests/unit/requests/test_download.py+70Lines changed: 70 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
1274 | 1274 | |
1275 | 1275 | |
1276 | 1276 | |
| 1277 | + |
| 1278 | + |
| 1279 | + |
| 1280 | + |
| 1281 | + |
| 1282 | + |
| 1283 | + |
| 1284 | + |
| 1285 | + |
| 1286 | + |
| 1287 | + |
| 1288 | + |
| 1289 | + |
| 1290 | + |
| 1291 | + |
| 1292 | + |
| 1293 | + |
| 1294 | + |
| 1295 | + |
| 1296 | + |
| 1297 | + |
| 1298 | + |
| 1299 | + |
| 1300 | + |
| 1301 | + |
| 1302 | + |
| 1303 | + |
| 1304 | + |
| 1305 | + |
| 1306 | + |
| 1307 | + |
1277 | 1308 | |
1278 | 1309 | |
1279 | 1310 | |
| ||
1290 | 1321 | |
1291 | 1322 | |
1292 | 1323 | |
| 1324 | + |
| 1325 | + |
| 1326 | + |
| 1327 | + |
| 1328 | + |
| 1329 | + |
| 1330 | + |
| 1331 | + |
| 1332 | + |
| 1333 | + |
| 1334 | + |
| 1335 | + |
| 1336 | + |
| 1337 | + |
| 1338 | + |
| 1339 | + |
| 1340 | + |
| 1341 | + |
| 1342 | + |
| 1343 | + |
| 1344 | + |
| 1345 | + |
| 1346 | + |
| 1347 | + |
| 1348 | + |
| 1349 | + |
| 1350 | + |
| 1351 | + |
| 1352 | + |
| 1353 | + |
| 1354 | + |
| 1355 | + |
| 1356 | + |
| 1357 | + |
| 1358 | + |
| 1359 | + |
| 1360 | + |
| 1361 | + |
| 1362 | + |
1293 | 1363 | |
1294 | 1364 | |
1295 | 1365 | |
|
Collapse file
packages/google-resumable-media/tests_async/unit/requests/test_download.py
Copy file name to clipboardExpand all lines: packages/google-resumable-media/tests_async/unit/requests/test_download.py+15Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
761 | 761 | |
762 | 762 | |
763 | 763 | |
| 764 | + |
| 765 | + |
| 766 | + |
| 767 | + |
| 768 | + |
| 769 | + |
| 770 | + |
| 771 | + |
| 772 | + |
| 773 | + |
| 774 | + |
| 775 | + |
| 776 | + |
| 777 | + |
| 778 | + |
764 | 779 | |
765 | 780 | |
766 | 781 | |
|
0 commit comments