-
Notifications
You must be signed in to change notification settings - Fork 387
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
Chunked body as an iterator doesn't work when body is a streamed iterator #846
Comments
Here is a better patch, for stream objects ( 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) |
sathieu
added a commit
to sathieu/vcrpy
that referenced
this issue
Jun 27, 2024
Fixes: kevin1024#846 Signed-off-by: Mathieu Parent <math.parent@gmail.com>
Created: #847 |
sathieu
added a commit
to sathieu/vcrpy
that referenced
this issue
Jun 29, 2024
Fixes: kevin1024#846 Signed-off-by: Mathieu Parent <math.parent@gmail.com>
sathieu
added a commit
to sathieu/vcrpy
that referenced
this issue
Jun 30, 2024
Fixes: kevin1024#846 Signed-off-by: Mathieu Parent <math.parent@gmail.com>
sathieu
added a commit
to sathieu/vcrpy
that referenced
this issue
Jul 2, 2024
Fixes: kevin1024#846 Signed-off-by: Mathieu Parent <math.parent@gmail.com>
sathieu
added a commit
to sathieu/vcrpy
that referenced
this issue
Jul 7, 2024
Fixes: kevin1024#846 Signed-off-by: Mathieu Parent <math.parent@gmail.com>
sathieu
added a commit
to sathieu/vcrpy
that referenced
this issue
Jul 14, 2024
Fixes: kevin1024#846 Signed-off-by: Mathieu Parent <math.parent@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#739 fixed chunked response for most of the usecases, but this is not enough 😉 .
When
list(body)
is processed, this consumes the iterator.:vcrpy/vcr/matchers.py
Line 91 in 86b114f
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 ...
The text was updated successfully, but these errors were encountered: