Browse files

Substitute a .gzt extension for .gz extensions to avoid an issue with…

… Safari in OSX
  • Loading branch information...
1 parent 2d3f235 commit 77ed400013c10de51edf1f493b478e077d9e45d7 @radicalbiscuit radicalbiscuit committed Jun 5, 2013
Showing with 14 additions and 8 deletions.
  1. +7 −1 README.rst
  2. +3 −3 mediasync/backends/s3.py
  3. +2 −2 mediasync/templatetags/media.py
  4. +2 −2 mediasync/tests/tests.py
View
8 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
=======
View
6 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)
View
4 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:
View
4 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()

0 comments on commit 77ed400

Please sign in to comment.