From b185a3ab69c1672431dc9eb33504969f1febf0ef Mon Sep 17 00:00:00 2001 From: Casey Ransom Date: Tue, 9 Apr 2024 11:59:13 -0400 Subject: [PATCH] Set json files to correct content-type They are currently inheriting a default mime/content type, 'binary/octet-stream', and they aren't qualified to be compressed inline by the CDN. Switching to 'application/json' allows clients that specify an 'accept-encoding' for the cloudfront/et al to compress the stream. --- src/zinc/storages/aws.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/zinc/storages/aws.py b/src/zinc/storages/aws.py index 9af9bf2..1389f88 100644 --- a/src/zinc/storages/aws.py +++ b/src/zinc/storages/aws.py @@ -91,11 +91,14 @@ def get_meta(self, subpath): def put(self, subpath, fileobj, max_age=None, **kwargs): log.debug(f"S3StorageBackend: put() called. (subpath: '{subpath}', max_age: {max_age})") - extra_args = None + extra_args = dict() if max_age is not None: extra_args = { 'CacheControl': f'max-age={max_age}' } + if subpath.endswith('.json'): + extra_args['ContentType'] = 'application/json' + keyname = self._get_keyname(subpath) self._bucket.upload_fileobj(fileobj, keyname, ExtraArgs=extra_args)