1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-08 16:53:23 +00:00

Make VCRHTTPResponse interface satisfy urllib3.response.HTTPResponse

This commit is contained in:
Sebastian Pipping
2023-05-16 15:42:53 +02:00
parent f1b921c211
commit 3547ed966f

View File

@@ -144,6 +144,28 @@ class VCRHTTPResponse(HTTPResponse):
def readable(self):
return self._content.readable()
@property
def length_remaining(self):
return self._content.getbuffer().nbytes - self._content.tell()
def get_redirect_location(self):
"""
Returns (a) redirect location string if we got a redirect
status code and valid location, (b) None if redirect status and
no location, (c) False if not a redirect status code.
See https://urllib3.readthedocs.io/en/stable/reference/urllib3.response.html .
"""
if not (300 <= self.status <= 399):
return False
return self.getheader("Location")
@property
def data(self):
return self._content.getbuffer().tobytes()
def drain_conn(self):
pass
class VCRConnection:
# A reference to the cassette that's currently being patched in