Skip to content

Commit

Permalink
Trivial fix and a test (for old requests versions) for psf#137.
Browse files Browse the repository at this point in the history
  • Loading branch information
elnuno committed Apr 11, 2017
1 parent 861be44 commit 60f00bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cachecontrol/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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.')
# 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')

0 comments on commit 60f00bd

Please sign in to comment.