Skip to content

Commit

Permalink
Substitute a .gzt extension for .gz extensions to avoid an issue with…
Browse files Browse the repository at this point in the history
… Safari in OSX
  • Loading branch information
radicalbiscuit committed Jun 5, 2013
1 parent 2d3f235 commit 77ed400
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
8 changes: 7 additions & 1 deletion README.rst
Expand Up @@ -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
=======
Expand Down
6 changes: 3 additions & 3 deletions mediasync/backends/s3.py
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions mediasync/templatetags/media.py
Expand Up @@ -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('/'))
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions mediasync/tests/tests.py
Expand Up @@ -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()

Expand Down

0 comments on commit 77ed400

Please sign in to comment.