diff --git a/docs/backends/azure.rst b/docs/backends/azure.rst index 8683cdd16..2cfdbc331 100644 --- a/docs/backends/azure.rst +++ b/docs/backends/azure.rst @@ -159,3 +159,9 @@ The following settings are available: A token credential used to authenticate HTTPS requests. The token value should be updated before its expiration. + + +``AZURE_CACHE_CONTROL`` + + A variable to set the Cache-Control HTTP response header. E.g. + ``AZURE_CACHE_CONTROL = "public,max-age=31536000,immutable"`` diff --git a/storages/backends/azure_storage.py b/storages/backends/azure_storage.py index 20925b551..153ab3d66 100644 --- a/storages/backends/azure_storage.py +++ b/storages/backends/azure_storage.py @@ -134,6 +134,7 @@ class AzureStorage(Storage): overwrite_files = setting('AZURE_OVERWRITE_FILES', False) location = setting('AZURE_LOCATION', '') default_content_type = 'application/octet-stream' + cache_control = setting("AZURE_CACHE_CONTROL") is_emulated = setting('AZURE_EMULATED_MODE', False) endpoint_suffix = setting('AZURE_ENDPOINT_SUFFIX') sas_token = setting('AZURE_SAS_TOKEN') @@ -255,7 +256,8 @@ def _save(self, name, content): stream=content, content_settings=ContentSettings( content_type=content_type, - content_encoding=content_encoding), + content_encoding=content_encoding, + cache_control=self.cache_control), max_connections=self.upload_max_conn, timeout=self.timeout) return cleaned_name diff --git a/tests/test_azure.py b/tests/test_azure.py index 1f9874679..71f413e31 100644 --- a/tests/test_azure.py +++ b/tests/test_azure.py @@ -304,7 +304,8 @@ def test_storage_save(self): timeout=20) c_mocked.assert_called_once_with( content_type='text/plain', - content_encoding=None) + content_encoding=None, + cache_control=None) def test_storage_open_write(self): """