diff --git a/storage/google/cloud/storage/blob.py b/storage/google/cloud/storage/blob.py index 21d92acd955a..a02afea14a6b 100644 --- a/storage/google/cloud/storage/blob.py +++ b/storage/google/cloud/storage/blob.py @@ -482,8 +482,9 @@ def download_to_file(self, file_obj, client=None): """ download_url = self._get_download_url() headers = _get_encryption_headers(self._encryption_key) - transport = self._get_transport(client) + headers['accept-encoding'] = 'gzip' + transport = self._get_transport(client) try: self._do_download(transport, file_obj, download_url, headers) except resumable_media.InvalidResponse as exc: diff --git a/storage/tests/unit/test_blob.py b/storage/tests/unit/test_blob.py index 9ce326d818c4..b1ee48a158e1 100644 --- a/storage/tests/unit/test_blob.py +++ b/storage/tests/unit/test_blob.py @@ -472,6 +472,7 @@ def _check_session_mocks(self, client, transport, # **MUTABLE** headers and it was mutated before the # second request. headers['range'] = 'bytes=3-5' + headers['accept-encoding'] = 'gzip' call = mock.call( 'GET', expected_url, data=None, headers=headers) self.assertEqual(transport.request.mock_calls, [call, call]) @@ -557,7 +558,8 @@ def test_download_to_file_with_failure(self): self.assertEqual(file_obj.tell(), 0) # Check that the transport was called once. transport.request.assert_called_once_with( - 'GET', blob.media_link, data=None, headers={}, stream=True) + 'GET', blob.media_link, data=None, + headers={'accept-encoding': 'gzip'}, stream=True) def test_download_to_file_wo_media_link(self): blob_name = 'blob-name' @@ -612,7 +614,8 @@ def _download_to_file_helper(self, use_chunks=False): self._check_session_mocks(client, transport, media_link) else: transport.request.assert_called_once_with( - 'GET', media_link, data=None, headers={}, stream=True) + 'GET', media_link, data=None, + headers={'accept-encoding': 'gzip'}, stream=True) def test_download_to_file_default(self): self._download_to_file_helper() @@ -677,7 +680,8 @@ def test_download_to_filename_w_key(self): 'updated': '2014-12-06T13:13:50.690Z'} key = b'aa426195405adee2c8081bb9e7e74b19' blob = self._make_one( - blob_name, bucket=bucket, properties=properties, encryption_key=key) + blob_name, bucket=bucket, properties=properties, + encryption_key=key) # Modify the blob so there there will be 2 chunks of size 3. blob._CHUNK_SIZE_MULTIPLE = 1 blob.chunk_size = 3 @@ -698,6 +702,7 @@ def test_download_to_filename_w_key(self): 'X-Goog-Encryption-Key-Sha256': header_key_hash_value, 'X-Goog-Encryption-Algorithm': 'AES256', 'X-Goog-Encryption-Key': header_key_value, + 'accept-encoding': 'gzip', } self._check_session_mocks( client, transport, media_link, headers=key_headers) @@ -1522,8 +1527,8 @@ def test_set_iam_policy(self): self.assertEqual(len(sent['bindings']), len(BINDINGS)) key = operator.itemgetter('role') for found, expected in zip( - sorted(sent['bindings'], key=key), - sorted(BINDINGS, key=key)): + sorted(sent['bindings'], key=key), + sorted(BINDINGS, key=key)): self.assertEqual(found['role'], expected['role']) self.assertEqual( sorted(found['members']), sorted(expected['members']))