... | ... |
@@ -339,10 +339,17 @@ class S3(object): |
339 | 339 |
|
340 | 340 |
return response |
341 | 341 |
|
342 |
- def add_encoding(self, filename): |
|
342 |
+ def add_encoding(self, filename, content_type): |
|
343 |
+ if content_type.find("charset=") != -1: |
|
344 |
+ return False |
|
345 |
+ exts = self.config.add_encoding_exts.split(',') |
|
346 |
+ if exts[0]=='': |
|
347 |
+ return False |
|
343 | 348 |
parts = filename.rsplit('.',2) |
349 |
+ if len(parts) < 2: |
|
350 |
+ return False |
|
344 | 351 |
ext = parts[1] |
345 |
- if ext in self.config.add_encoding_ext: |
|
352 |
+ if ext in exts: |
|
346 | 353 |
return True |
347 | 354 |
else: |
348 | 355 |
return False |
... | ... |
@@ -367,13 +374,14 @@ class S3(object): |
367 | 367 |
|
368 | 368 |
## MIME-type handling |
369 | 369 |
content_type = self.config.mime_type |
370 |
+ print(content_type) |
|
370 | 371 |
if not content_type and self.config.guess_mime_type: |
371 | 372 |
content_type = mime_magic(filename) |
372 | 373 |
if not content_type: |
373 | 374 |
content_type = self.config.default_mime_type |
374 |
- |
|
375 |
+ print(content_type) |
|
375 | 376 |
## add charset to content type |
376 |
- if self.add_encoding(filename): |
|
377 |
+ if self.add_encoding(filename, content_type): |
|
377 | 378 |
content_type = content_type + ";charset=" + self.config.encoding.upper() |
378 | 379 |
|
379 | 380 |
debug("Content-Type set to '%s'" % content_type) |
... | ... |
@@ -1524,7 +1524,7 @@ def main(): |
1524 | 1524 |
optparser.add_option( "--add-header", dest="add_header", action="append", metavar="NAME:VALUE", help="Add a given HTTP header to the upload request. Can be used multiple times. For instance set 'Expires' or 'Cache-Control' headers (or both) using this options if you like.") |
1525 | 1525 |
|
1526 | 1526 |
optparser.add_option( "--encoding", dest="encoding", metavar="ENCODING", help="Override autodetected terminal and filesystem encoding (character set). Autodetected: %s" % preferred_encoding) |
1527 |
- optparser.add_option( "--add-encoding-ext", dest="add_encoding_ext", action="append", metavar="EXTENSION", help="Add encoding to this ext when uploading to S3, may be used multiple times") |
|
1527 |
+ optparser.add_option( "--add-encoding-exts", dest="add_encoding_exts", metavar="EXTENSIONs", help="Add encoding to these comma delimited extensions i.e. (css,js,html) when uploading to S3 )") |
|
1528 | 1528 |
optparser.add_option( "--verbatim", dest="urlencoding_mode", action="store_const", const="verbatim", help="Use the S3 name as given on the command line. No pre-processing, encoding, etc. Use with caution!") |
1529 | 1529 |
|
1530 | 1530 |
optparser.add_option( "--disable-multipart", dest="enable_multipart", action="store_false", help="Disable multipart upload on files bigger than --multipart-chunk-size-mb") |