Skip to content

Commit

Permalink
Azure: Added Cache-Control header support (#780)
Browse files Browse the repository at this point in the history
* Added Cache-Control header support for Azure backend

The HTTP header value can be controlled via the AZURE_CACHE_CONTROL environment variable.
For example: AZURE_CACHE_CONTROL="public, max-age=31536000"

* Fix tests
  • Loading branch information
rriski authored and jschneier committed Nov 18, 2019
1 parent f94c065 commit 6a4bbd4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/backends/azure.rst
Expand Up @@ -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"``
4 changes: 3 additions & 1 deletion storages/backends/azure_storage.py
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_azure.py
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 6a4bbd4

Please sign in to comment.