Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no chunked attr #151

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion cachecontrol/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 16 additions & 1 deletion tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might reword this as Requests version supports chucked. Skipping this test.

# delattr(response, 'chunked')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this comment?

return super().build_response(request, response, from_cache,
cacheable_methods)
sess = Session()
sess.mount('http://', NoChunked())
sess.get('http://httpbin.org/cache/60')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to assert something here! :)