From 77ed400013c10de51edf1f493b478e077d9e45d7 Mon Sep 17 00:00:00 2001 From: Bradley Gentry Date: Wed, 5 Jun 2013 15:23:43 -0400 Subject: [PATCH] Substitute a .gzt extension for .gz extensions to avoid an issue with Safari in OSX --- README.rst | 8 +++++++- mediasync/backends/s3.py | 6 +++--- mediasync/templatetags/media.py | 4 ++-- mediasync/tests/tests.py | 4 ++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index ee20561..c96a1c4 100644 --- a/README.rst +++ b/README.rst @@ -607,7 +607,13 @@ and direct the user to the appropriate file based on the ACCEPT_ENCODING HTTP header. Assuming a file styles/layout.css, the following would be synced to S3:: styles/layout.css - styles/layout.css.gz + styles/layout.css.gzt + +Note the altered use of the .gz extension. Some versions of the Safari browser +on OSX ignore the Content-Type header for files ending in .gz and treat them +instead as files to download. This altered extension allows Safari to deflate +and utilize the files correctly without affecting functionality in any other +tested browsers. Signals ======= diff --git a/mediasync/backends/s3.py b/mediasync/backends/s3.py index 0a5f831..30e5abc 100644 --- a/mediasync/backends/s3.py +++ b/mediasync/backends/s3.py @@ -90,12 +90,12 @@ def put(self, filedata, content_type, remote_path, force=False): # check to see if file should be gzipped based on content_type # also check to see if filesize is greater than 1kb if content_type in TYPES_TO_COMPRESS: - - key = Key(self._bucket, "%s.gz" % remote_path) + # Use a .gzt extension to avoid issues with Safari on OSX + key = Key(self._bucket, "%s.gzt" % remote_path) filedata = mediasync.compress(filedata) (hexdigest, b64digest) = mediasync.checksum(filedata) # update checksum with compressed data - headers["Content-Disposition"] = 'inline; filename="%sgz"' % remote_path.split('/')[-1] + headers["Content-Disposition"] = 'inline; filename="%sgzt"' % remote_path.split('/')[-1] headers["Content-Encoding"] = 'gzip' key.set_metadata('mediasync-checksum', raw_b64digest) diff --git a/mediasync/templatetags/media.py b/mediasync/templatetags/media.py index 4ace5e3..b066e66 100644 --- a/mediasync/templatetags/media.py +++ b/mediasync/templatetags/media.py @@ -63,7 +63,7 @@ def mkpath(self, url, path, filename=None, gzip=False): path: (str) The path on the host (specified in 'url') leading up to the file. filename: (str) The file name to serve. - gzip: (bool) True if client should receive *.gz version of file. + gzip: (bool) True if client should receive *.gzt version of file. """ if path: url = "%s/%s" % (url.rstrip('/'), path.strip('/')) @@ -73,7 +73,7 @@ def mkpath(self, url, path, filename=None, gzip=False): content_type = mimetypes.guess_type(url)[0] if gzip and content_type in mediasync.TYPES_TO_COMPRESS: - url = "%s.gz" % url + url = "%s.gzt" % url cb = msettings['CACHE_BUSTER'] if cb: diff --git a/mediasync/tests/tests.py b/mediasync/tests/tests.py index ecac79a..c6aab9c 100644 --- a/mediasync/tests/tests.py +++ b/mediasync/tests/tests.py @@ -239,10 +239,10 @@ def testSync(self): if content_type in mediasync.TYPES_TO_COMPRESS: - key = bucket.get_key("%s.gz" % path) + key = bucket.get_key("%s.gzt" % path) # do a HEAD request on the file - http_conn.request('HEAD', "/%s/%s.gz" % (self.bucket_name, path)) + http_conn.request('HEAD', "/%s/%s.gzt" % (self.bucket_name, path)) response = http_conn.getresponse() response.read()