diff --git a/apitools/base/py/transfer.py b/apitools/base/py/transfer.py index f4cd8bb3..402281f6 100644 --- a/apitools/base/py/transfer.py +++ b/apitools/base/py/transfer.py @@ -982,13 +982,8 @@ def __SendMediaBody(self, start, additional_headers=None): if self.total_size is None: raise exceptions.TransferInvalidError( 'Total size must be known for SendMediaBody') - # Change body_stream from a stream to a string object. This is - # because httpwrapper.MakeRequest doesn't handle the case where - # request.body is a stream. In the case that the body is a stream, - # if a request has to be retried, then the stream will be exhausted - # and the request will hang. body_stream = stream_slice.StreamSlice( - self.stream, self.total_size - start).read() + self.stream, self.total_size - start) request = http_wrapper.Request(url=self.url, http_method='PUT', body=body_stream) diff --git a/apitools/base/py/transfer_test.py b/apitools/base/py/transfer_test.py index dd5b9eba..e1080fa5 100644 --- a/apitools/base/py/transfer_test.py +++ b/apitools/base/py/transfer_test.py @@ -531,35 +531,3 @@ def testRetryRequestChunks(self): # Ensure the mock was called the correct number of times. self.assertEquals(make_request.call_count, len(responses)) - - def testRetryRequestMedia(self): - """Test that StreamMedia will retry correctly.""" - # Create and configure the upload object. - bytes_http = httplib2.Http() - upload = transfer.Upload( - stream=self.sample_stream, - mime_type='text/plain', - total_size=len(self.sample_data), - close_stream=False, - http=bytes_http) - - upload.strategy = transfer.RESUMABLE_UPLOAD - # Set the chunk size so the entire stream is uploaded. - upload.chunksize = len(self.sample_data) - # Mock the upload to return the sample response. - with mock.patch.object(bytes_http, - 'request') as make_request: - # This side effect also checks the request body. - responses = [ - self.response, # Initial request in InitializeUpload(). - self.fail_response, # 503 status code from server. - self.response # Successful request. - ] - make_request.side_effect = self.HttpRequestSideEffect(responses) - - # Initialization. - upload.InitializeUpload(self.request, bytes_http) - upload.StreamMedia() - - # Ensure the mock was called the correct number of times.. - self.assertEquals(make_request.call_count, len(responses))