Skip to content

Commit

Permalink
Ensure body is consumed only once
Browse files Browse the repository at this point in the history
Fixes: kevin1024#846
Signed-off-by: Mathieu Parent <math.parent@gmail.com>
  • Loading branch information
sathieu committed Jun 27, 2024
1 parent 86b114f commit aa91203
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vcr/stubs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ def getresponse(self, _=False, **kwargs):
"""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)
Expand Down

0 comments on commit aa91203

Please sign in to comment.