This commit is contained in:
SunDwarf
2015-11-19 17:34:47 +00:00
4 changed files with 19 additions and 12 deletions
+2 -1
View File
@@ -6,4 +6,5 @@ Contributors
* Hannes Ljungberg (hannseman)
* Erik Taubeneck (eriktaubeneck)
* Frank Tackitt (kageurufu)
* Isaac Dickinson (SunDwarf)
* Isaac Dickinson (SunDwarf)
* bool-dev
+2
View File
@@ -232,6 +232,8 @@ uploading assets to S3.
`S3_GZIP` Compress all assets using GZIP and set the
corresponding Content-Type and Content-Encoding
headers on the S3 files.
`S3_FORCE_MIMETYPE` Always set the Content-Type header on the S3 files
irrespective of gzipping. Defaults to `False`.
=========================== ===================================================
.. _debug: http://flask.pocoo.org/docs/config/#configuration-basics
+14 -10
View File
@@ -182,6 +182,7 @@ def _write_files(s3, app, static_url_loc, static_folder, files, bucket,
ex_keys=None, hashes=None):
""" Writes all the files inside a static folder to S3. """
should_gzip = app.config.get('S3_GZIP')
add_mime = app.config.get('S3_FORCE_MIMETYPE')
new_hashes = []
static_folder_rel = _path_to_relative_url(static_folder)
for file_path in files:
@@ -215,15 +216,17 @@ def _write_files(s3, app, static_url_loc, static_folder, files, bucket,
if should_gzip:
h["content-encoding"] = "gzip"
if "content-type" not in h:
# When we use GZIP we have to explicitly set the content type
(mimetype, encoding) = mimetypes.guess_type(file_path,
False)
if mimetype:
h["content-type"] = mimetype
else:
logger.warn("Unable to detect mimetype for %s" %
file_path)
if add_mime or should_gzip and "content-type" not in h:
# When we use GZIP we have to explicitly set the content type
# or if the mime flag is True
(mimetype, encoding) = mimetypes.guess_type(file_path,
False)
if mimetype:
h["content-type"] = mimetype
else:
logger.warn("Unable to detect mimetype for %s" %
file_path)
with open(file_path) as fp:
metadata, params = split_metadata_params(merge_two_dicts(app.config['S3_HEADERS'], h))
@@ -401,7 +404,8 @@ class FlaskS3(object):
('S3_FILEPATH_HEADERS', {}),
('S3_ONLY_MODIFIED', False),
('S3_URL_STYLE', 'host'),
('S3_GZIP', False)]
('S3_GZIP', False),
('S3_FORCE_MIMETYPE', False)]
for k, v in defaults:
app.config.setdefault(k, v)
+1 -1
View File
@@ -9,7 +9,7 @@ from setuptools import setup
setup(
name='Flask-S3',
version='0.2.5',
version='0.2.6',
url='http://github.com/e-dard/flask-s3',
license='WTFPL',
author='Edward Robinson',