Skip to content

Commit

Permalink
Set json files to correct content-type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cransom committed Apr 9, 2024
1 parent 50e68b3 commit b185a3a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/zinc/storages/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit b185a3a

Please sign in to comment.