File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,9 @@ module.exports = {
29
29
s3DeployClient : function ( /* context */ ) {
30
30
return new S3 ( { plugin : this } ) ;
31
31
} ,
32
+ gzippedFiles : function ( context ) {
33
+ return context . gzippedFiles || [ ] ;
34
+ } ,
32
35
allowOverwrite : false
33
36
} ,
34
37
@@ -41,6 +44,7 @@ module.exports = {
41
44
var revisionKey = this . readConfig ( 'revisionKey' ) ;
42
45
var distDir = this . readConfig ( 'distDir' ) ;
43
46
var filePattern = this . readConfig ( 'filePattern' ) ;
47
+ var gzippedFiles = this . readConfig ( 'gzippedFiles' ) ;
44
48
var allowOverwrite = this . readConfig ( 'allowOverwrite' ) ;
45
49
var filePath = path . join ( distDir , filePattern ) ;
46
50
@@ -51,6 +55,7 @@ module.exports = {
51
55
filePattern : filePattern ,
52
56
filePath : filePath ,
53
57
revisionKey : revisionKey ,
58
+ gzippedFilePaths : gzippedFiles ,
54
59
allowOverwrite : allowOverwrite
55
60
} ;
56
61
Original file line number Diff line number Diff line change @@ -36,13 +36,15 @@ module.exports = CoreObject.extend({
36
36
} ,
37
37
38
38
upload : function ( options ) {
39
- var client = this . _client ;
40
- var plugin = this . _plugin ;
41
- var bucket = options . bucket ;
42
- var acl = options . acl ;
43
- var allowOverwrite = options . allowOverwrite ;
44
- var key = path . join ( options . prefix , options . filePattern + ":" + options . revisionKey ) ;
45
- var putObject = Promise . denodeify ( client . putObject . bind ( client ) ) ;
39
+ var client = this . _client ;
40
+ var plugin = this . _plugin ;
41
+ var bucket = options . bucket ;
42
+ var acl = options . acl ;
43
+ var allowOverwrite = options . allowOverwrite ;
44
+ var key = path . join ( options . prefix , options . filePattern + ":" + options . revisionKey ) ;
45
+ var putObject = Promise . denodeify ( client . putObject . bind ( client ) ) ;
46
+ var gzippedFilePaths = options . gzippedFilePaths || [ ] ;
47
+ var isGzipped = gzippedFilePaths . indexOf ( 'index.html' ) !== - 1 ;
46
48
47
49
var params = {
48
50
Bucket : bucket ,
@@ -52,6 +54,10 @@ module.exports = CoreObject.extend({
52
54
CacheControl : 'max-age=0, no-cache'
53
55
}
54
56
57
+ if ( isGzipped ) {
58
+ params . ContentEncoding = 'gzip' ;
59
+ }
60
+
55
61
return this . fetchRevisions ( options )
56
62
. then ( function ( revisions ) {
57
63
var found = revisions . map ( function ( element ) { return element . revision ; } ) . indexOf ( options . revisionKey ) ;
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ describe('s3', function() {
73
73
bucket : bucket ,
74
74
prefix : '' ,
75
75
acl : 'public-read' ,
76
+ gzippedFilePaths : [ ] ,
76
77
filePattern : filePattern ,
77
78
revisionKey : revisionKey ,
78
79
filePath : 'tests/unit/fixtures/test.html' ,
@@ -137,6 +138,16 @@ describe('s3', function() {
137
138
} ) ;
138
139
} ) ;
139
140
141
+ it ( 'sets the Content-Encoding header to gzip when the index file is gziped' , function ( ) {
142
+ options . gzippedFilePaths = [ 'index.html' ] ;
143
+ var promise = subject . upload ( options ) ;
144
+
145
+ return assert . isFulfilled ( promise )
146
+ . then ( function ( ) {
147
+ assert . equal ( s3Params . ContentEncoding , 'gzip' , 'contentEncoding is set to gzip' ) ;
148
+ } ) ;
149
+ } ) ;
150
+
140
151
it ( 'allows `prefix` option to be passed to customize upload-path' , function ( ) {
141
152
var prefix = 'my-app' ;
142
153
You can’t perform that action at this time.
0 commit comments