diff --git a/cachecontrol/adapter.py b/cachecontrol/adapter.py index 195d49d9..defa1147 100644 --- a/cachecontrol/adapter.py +++ b/cachecontrol/adapter.py @@ -102,7 +102,7 @@ def build_response(self, request, response, from_cache=False, response, ) ) - if response.chunked: + if hasattr(response, 'chunked') and response.chunked: super_update_chunk_length = response._update_chunk_length def _update_chunk_length(self): diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 33e0edf3..9efd9ced 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -2,7 +2,7 @@ import pytest -from cachecontrol import CacheControl +from cachecontrol import CacheControl, CacheControlAdapter from cachecontrol.caches import FileCache from cachecontrol.filewrapper import CallbackFileWrapper from requests import Session @@ -29,3 +29,18 @@ def test_getattr_during_gc(): vars(s).clear() # gc does this. with pytest.raises(AttributeError): s.x + + +def test_handle_no_chunked_attr(): + + class NoChunked(CacheControlAdapter): + def build_response(self, request, response, from_cache=False, + cacheable_methods=None): + if hasattr(response, 'chunked'): + pytest.skip('Requests is new enough, test makes no sense.') + # delattr(response, 'chunked') + return super().build_response(request, response, from_cache, + cacheable_methods) + sess = Session() + sess.mount('http://', NoChunked()) + sess.get('http://httpbin.org/cache/60')