You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by cl...@apache.org on 2021/02/08 03:09:41 UTC

[libcloud] 01/01: Respect headers uploading Azure blob via stream

This is an automated email from the ASF dual-hosted git repository.

clewolff pushed a commit to branch storage-azureblobs-fix-1550-contentencoding
in repository https://gitbox.apache.org/repos/asf/libcloud.git

commit cf6756bbf36f5517e36e2e780340c19c9ad7f016
Author: Clemens Wolff <cl...@microsoft.com>
AuthorDate: Sun Feb 7 22:08:53 2021 -0500

    Respect headers uploading Azure blob via stream
---
 CHANGES.rst                             | 12 ++++++++++++
 libcloud/storage/drivers/azure_blobs.py | 32 ++++++++++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/CHANGES.rst b/CHANGES.rst
index a99a8bd..9493dab 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,18 @@
 Changelog
 =========
 
+Changes in Apache Libcloud 3.3.2
+--------------------------------
+
+Storage
+~~~~~~~
+
+- [Azure Blobs] Respect Content-Encoding, Content-Language and Cache-Control
+  headers when uploading blobs via stream.
+
+  Reported by Veith Röthlingshöfer - @RunOrVeith.
+  (GITHUB-1550)
+
 Changes in Apache Libcloud 3.3.1
 --------------------------------
 
diff --git a/libcloud/storage/drivers/azure_blobs.py b/libcloud/storage/drivers/azure_blobs.py
index 3393784..baa8612 100644
--- a/libcloud/storage/drivers/azure_blobs.py
+++ b/libcloud/storage/drivers/azure_blobs.py
@@ -803,6 +803,7 @@ class AzureBlobsStorageDriver(StorageDriver):
         response = self._commit_blocks(object_path=object_path,
                                        chunks=chunks,
                                        lease=lease,
+                                       headers=headers,
                                        meta_data=meta_data,
                                        content_type=content_type,
                                        data_hash=data_hash,
@@ -822,7 +823,7 @@ class AzureBlobsStorageDriver(StorageDriver):
             'bytes_transferred': bytes_transferred,
         }
 
-    def _commit_blocks(self, object_path, chunks, lease,
+    def _commit_blocks(self, object_path, chunks, lease, headers,
                        meta_data, content_type, data_hash,
                        object_name, file_path):
         """
@@ -837,7 +838,7 @@ class AzureBlobsStorageDriver(StorageDriver):
 
         data = tostring(root)
         params = {'comp': 'blocklist'}
-        headers = {}
+        headers = headers or {}
 
         lease.update_headers(headers)
         lease.renew()
@@ -857,6 +858,8 @@ class AzureBlobsStorageDriver(StorageDriver):
 
         headers['Content-Length'] = len(data)
 
+        headers = self._fix_headers(headers)
+
         response = self.connection.request(object_path, data=data,
                                            params=params, headers=headers,
                                            method='PUT')
@@ -929,6 +932,31 @@ class AzureBlobsStorageDriver(StorageDriver):
 
         return False
 
+    def _fix_headers(self, headers):
+        """
+        Update common HTTP headers to their equivalent in Azure Storage
+
+        :param headers: The headers dictionary to be updated
+        :type headers: ``dict``
+        """
+        to_fix = (
+            'cache-control',
+            'content-encoding',
+            'content-language',
+        )
+
+        fixed = {}
+
+        for key, value in headers.items():
+            key_lower = key.lower()
+
+            if key_lower in to_fix:
+                fixed['x-ms-blob-%s' % key_lower] = value
+            else:
+                fixed[key] = value
+
+        return fixed
+
     def _update_metadata(self, headers, meta_data):
         """
         Update the given metadata in the headers