Skip to content

Commit

Permalink
Ensure body is consumed only once
Browse files Browse the repository at this point in the history
Fixes: #846
Signed-off-by: Mathieu Parent <[email protected]>
  • Loading branch information
sathieu committed Jun 29, 2024
1 parent 86b114f commit 9b0e9d9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vcr/stubs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ def endheaders(self, message_body=None):

def getresponse(self, _=False, **kwargs):
"""Retrieve the response"""
# Some file-like objects or iterators can only be consumed once
if hasattr(self._vcr_request.body, 'read'):
self._vcr_request.body = self._vcr_request.body.read()
elif not isinstance(self._vcr_request.body, (str, bytes, bytearray, list)):
self._vcr_request.body = list(self._vcr_request.body)
# Check to see if the cassette has a response for this request. If so,
# then return it
if self.cassette.can_play_response_for(self._vcr_request):
Expand Down

0 comments on commit 9b0e9d9

Please sign in to comment.