Skip to content

Commit

Permalink
Add header enabling gzip downloads (#3380)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignacio Tartavull authored and tseaver committed Oct 13, 2017
1 parent c171fdc commit 8762c34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion storage/google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 10 additions & 5 deletions storage/tests/unit/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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']))
Expand Down

0 comments on commit 8762c34

Please sign in to comment.