From 7fb1e18ee4419c1a120d40c31481a93848a2fb29 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Fri, 27 Aug 2021 14:50:42 -0400 Subject: [PATCH] add read to httpclienttransportresponse --- .../azure/core/pipeline/transport/_base.py | 13 ++++++------- .../azure/core/pipeline/transport/_base_async.py | 5 +++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/sdk/core/azure-core/azure/core/pipeline/transport/_base.py b/sdk/core/azure-core/azure/core/pipeline/transport/_base.py index 6b4a0d4e4839..634e40f656cc 100644 --- a/sdk/core/azure-core/azure/core/pipeline/transport/_base.py +++ b/sdk/core/azure-core/azure/core/pipeline/transport/_base.py @@ -537,13 +537,7 @@ def __init__(self, **kwargs): self.headers = _case_insensitive_dict(self._internal_response.getheaders()) self.reason = self._internal_response.reason self.content_type = self.headers.get("Content-Type") - self._data = None - - @property - def content(self): - if self._data is None: - self._data = self._internal_response.read() - return self._data + self._content = None class RestHttpClientTransportResponse(_RestHttpClientTransportResponse, RestHttpResponse): """Create a Rest HTTPResponse from an http.client response. @@ -555,6 +549,11 @@ def iter_bytes(self): def iter_raw(self): raise TypeError("We do not support iter_raw for this transport response") + def read(self): + if self._content is None: + self._content = self._internal_response.read() + return self._content + class BytesIOSocket(object): """Mocking the "makefile" of socket for HTTPResponse. diff --git a/sdk/core/azure-core/azure/core/pipeline/transport/_base_async.py b/sdk/core/azure-core/azure/core/pipeline/transport/_base_async.py index fe3b7fd3d593..115412ab4a83 100644 --- a/sdk/core/azure-core/azure/core/pipeline/transport/_base_async.py +++ b/sdk/core/azure-core/azure/core/pipeline/transport/_base_async.py @@ -171,6 +171,11 @@ async def iter_bytes(self): async def iter_raw(self): raise TypeError("We do not support iter_raw for this transport response") + async def read(self): + if self._content is None: + self._content = self._internal_response.read() + return self._content + class AsyncHttpTransport( AbstractAsyncContextManager,