Closed sathieu closed 3 months ago
Here is a better patch, for stream objects (BytesIO
) too:
diff --git a/vcr/stubs/__init__.py b/vcr/stubs/__init__.py
index 4d4bb39..2ea9fdf 100644
--- a/vcr/stubs/__init__.py
+++ b/vcr/stubs/__init__.py
@@ -254,6 +254,12 @@ class VCRConnection:
"""Retrieve the response"""
# Check to see if the cassette has a response for this request. If so,
# then return it
+ if self._vcr_request.headers.get('Transfer-Encoding', '') == 'chunked':
+ if not (isinstance(self._vcr_request.body, str) or isinstance(self._vcr_request.body, bytes) or isinstance(self._vcr_request.body, bytearray)):
+ if hasattr(self._vcr_request.body, 'read'):
+ self._vcr_request.body = self._vcr_request.body.read()
+ else:
+ self._vcr_request.body = list(self._vcr_request.body)
if self.cassette.can_play_response_for(self._vcr_request):
log.info(f"Playing response for {self._vcr_request} from cassette")
response = self.cassette.play_response(self._vcr_request)
https://github.com/kevin1024/vcrpy/pull/739 fixed chunked response for most of the usecases, but this is not enough :wink: .
When
list(body)
is processed, this consumes the iterator.:https://github.com/kevin1024/vcrpy/blob/86b114f2f569a9914b182718ab62090ad5913ba6/vcr/matchers.py#L91
But this code is called many times, and all but the first call will return an empty list.
This could be worked-around with:
But this is hackish and probably not the right place ...