s3_website 2.8.6 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 147c1079964479122eef8b8c049d8c14795b7605
4
- data.tar.gz: 4fac5c7fe84796797d2a242656f504be508caa52
3
+ metadata.gz: ee583948eaac40a396bdd7dcce3ac0f17b026b53
4
+ data.tar.gz: fb3b7ff28372c6844d2c637f59b8fbc1a08a112e
5
5
  SHA512:
6
- metadata.gz: df826a2926ecb33997c516c8dcf4f9a8af7f92a05cd0f1af5c18b7b8c860781a784c160ad139d5f7c927a23820e3bf72bd6235d74ce62c13b59cef445594c85e
7
- data.tar.gz: 796902606cb3a9c1aec1fb69a76decdbf6919b8bcfde45708444dc23dbefa964133b9b12d247dc2969bac9691375c9553fc65c561ddeadc21a0852d365055b20
6
+ metadata.gz: a06324e37ab33faa10ca761537336020dc2c712b980facfad0aece7fc3c010fafb1c2782c4878a5b566a85d3f5ca357756abfe9f1207847f3cd1b93ec7b23336
7
+ data.tar.gz: b7db3637d2582366540f0938f8fe3608340b1b74ff6ba308db40da17f794061fd382dedcdde8af090ac1713f182e27c2c5161bd8c7333dd25c993e3a025556d4
data/README.md CHANGED
@@ -91,8 +91,12 @@ incomprehensible or inconsistent.
91
91
 
92
92
  ### Cache Control
93
93
 
94
- You can use the `max_age` configuration option to enable more effective browser
95
- caching of your static assets. There are two possible ways to use the option:
94
+ You can use either the setting `max_age` or `cache_control`to enable more
95
+ effective browser caching of your static assets.
96
+
97
+ #### max_age
98
+
99
+ There are two possible ways to use the option:
96
100
  you can specify a single age (in seconds) like so:
97
101
 
98
102
  ```yaml
@@ -108,11 +112,23 @@ max_age:
108
112
  "*": 300
109
113
  ```
110
114
 
111
- Place the configuration into the file `s3_website.yml`.
112
-
113
115
  After changing the `max_age` setting, push with the `--force` option.
114
116
  Force-pushing allows you to update the S3 object metadata of existing files.
115
117
 
118
+ #### cache_control
119
+
120
+ The `cache_control` setting allows you to define an arbitrary string that s3_website
121
+ will put on all the S3 objects of your website.
122
+
123
+ Here's an example:
124
+
125
+ ```yaml
126
+ cache_control: public, no-transform, max-age=1200, s-maxage=1200
127
+ ```
128
+
129
+ After changing the `cache_control` setting, push with the `--force` option.
130
+ Force-pushing allows you to update the S3 object metadata of existing files.
131
+
116
132
  ### Gzip Compression
117
133
 
118
134
  If you choose, you can use compress certain file types before uploading them to
@@ -157,6 +173,8 @@ s3_endpoint: ap-northeast-1
157
173
  The valid `s3_endpoint` values consist of the [S3 location constraint
158
174
  values](http://docs.amazonwebservices.com/general/latest/gr/rande.html#s3_region).
159
175
 
176
+ Note that at the moment s3_website does not support the *eu-central-1* region.
177
+
160
178
  ### Ignoring files you want to keep on AWS
161
179
 
162
180
  Sometimes there are files or directories you want to keep on S3, but not on
data/changelog.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  This project uses [Semantic Versioning](http://semver.org).
4
4
 
5
+ ## 2.9.0
6
+
7
+ * Add setting `cache_control`
8
+
5
9
  ## 2.8.6
6
10
 
7
11
  * Detect changed file even though the file has the same contents with another file on the S3 bucket
@@ -1,3 +1,3 @@
1
1
  module S3Website
2
- VERSION = '2.8.6'
2
+ VERSION = '2.9.0'
3
3
  end
@@ -4,6 +4,7 @@ class Logger(val verboseOutput: Boolean, onLog: Option[(String) => _] = None) {
4
4
  def debug(msg: String) = if (verboseOutput) log(Debug, msg)
5
5
  def info(msg: String) = log(Info, msg)
6
6
  def fail(msg: String) = log(Failure, msg)
7
+ def warn(msg: String) = log(Warn, msg)
7
8
 
8
9
  def info(report: SuccessReport) = log(Success, report.reportMessage)
9
10
  def info(report: ErrorReport) = fail(report.reportMessage)
@@ -36,6 +37,9 @@ class Logger(val verboseOutput: Boolean, onLog: Option[(String) => _] = None) {
36
37
  case object Wait extends LogType {
37
38
  val prefix = "wait".yellow
38
39
  }
40
+ case object Warn extends LogType {
41
+ val prefix = "warn".yellow
42
+ }
39
43
 
40
44
  /**
41
45
  * Idea copied from https://github.com/ktoso/scala-rainbow.
@@ -61,7 +61,7 @@ object S3 {
61
61
  retryAction = newAttempt => this.delete(s3Key, newAttempt)
62
62
  )
63
63
 
64
- def toPutObjectRequest(source: Either[Upload, Redirect])(implicit config: Config): Try[PutObjectRequest] =
64
+ def toPutObjectRequest(source: Either[Upload, Redirect])(implicit config: Config, logger: Logger): Try[PutObjectRequest] =
65
65
  source.fold(
66
66
  upload =>
67
67
  for {
@@ -72,14 +72,20 @@ object S3 {
72
72
  md setContentLength uploadFile.length
73
73
  md setContentType contentType
74
74
  upload.encodingOnS3.map(_ => "gzip") foreach md.setContentEncoding
75
- upload.maxAge foreach { seconds =>
76
- md.setCacheControl(
77
- if (seconds == 0)
78
- s"no-cache; max-age=$seconds"
79
- else
80
- s"max-age=$seconds"
81
- )
75
+ val cacheControl: Option[String] = (upload.maxAge, config.cache_control) match {
76
+ case (maxAge: Some[Int], cacheCtrl: Some[String]) =>
77
+ logger.warn("Overriding the max_age setting with the cache_control setting")
78
+ cacheCtrl
79
+ case (_, cacheCtrl: Some[String]) =>
80
+ cacheCtrl
81
+ case (maxAgeSeconds: Some[int], None) =>
82
+ maxAgeSeconds.map({
83
+ case seconds if seconds == 0 => s"no-cache; max-age=0"
84
+ case seconds => s"max-age=$seconds"
85
+ })
86
+ case (None, None) => None
82
87
  }
88
+ cacheControl foreach { md.setCacheControl }
83
89
  val req = new PutObjectRequest(config.s3_bucket, upload.s3Key, new FileInputStream(uploadFile), md)
84
90
  config.s3_reduced_redundancy.filter(_ == true) foreach (_ => req setStorageClass ReducedRedundancy)
85
91
  req
@@ -15,6 +15,7 @@ case class Config(
15
15
  s3_endpoint: S3Endpoint,
16
16
  site: Option[String],
17
17
  max_age: Option[Either[Int, Map[String, Int]]],
18
+ cache_control: Option[String],
18
19
  gzip: Option[Either[Boolean, Seq[String]]],
19
20
  gzip_zopfli: Option[Boolean],
20
21
  ignore_on_server: Option[Either[String, Seq[String]]],
@@ -40,6 +40,7 @@ object Site {
40
40
  s3_endpoint <- loadEndpoint.right
41
41
  site <- loadOptionalString("site").right
42
42
  max_age <- loadMaxAge.right
43
+ cache_control <- loadOptionalString("cache_control").right
43
44
  gzip <- loadOptionalBooleanOrStringSeq("gzip").right
44
45
  gzip_zopfli <- loadOptionalBoolean("gzip_zopfli").right
45
46
  extensionless_mime_type <- loadOptionalString("extensionless_mime_type").right
@@ -66,6 +67,7 @@ object Site {
66
67
  s3_endpoint getOrElse S3Endpoint.defaultEndpoint,
67
68
  site,
68
69
  max_age,
70
+ cache_control,
69
71
  gzip,
70
72
  gzip_zopfli,
71
73
  ignore_on_server = ignore_on_server,
@@ -477,6 +477,46 @@ class S3WebsiteSpec extends Specification {
477
477
  }
478
478
  }
479
479
 
480
+ "cache_control in config" should {
481
+ "be applied to all files" in new BasicSetup {
482
+ config = "cache_control: public, no-transform, max-age=1200, s-maxage=1200"
483
+ setLocalFile("index.html")
484
+ push()
485
+ sentPutObjectRequest.getMetadata.getCacheControl must equalTo("public, no-transform, max-age=1200, s-maxage=1200")
486
+ }
487
+
488
+ "should take precedence over max_age" in new BasicSetup {
489
+ config = """
490
+ |max_age: 120
491
+ |cache_control: public, max-age=90
492
+ """.stripMargin
493
+ setLocalFile("index.html")
494
+ push()
495
+ sentPutObjectRequest.getMetadata.getCacheControl must equalTo("public, max-age=90")
496
+ }
497
+
498
+ "log a warning if both cache_control and max_age are present" in new BasicSetup {
499
+ val logEntries = new mutable.MutableList[String]
500
+ config = """
501
+ |max_age: 120
502
+ |cache_control: public, max-age=90
503
+ """.stripMargin
504
+ setLocalFile("index.html")
505
+ push(logCapturer = Some((logEntry: String) =>
506
+ logEntries += logEntry
507
+ ))
508
+ logEntries must contain("[\u001B[33mwarn\u001B[0m] Overriding the max_age setting with the cache_control settin")
509
+ }
510
+ }
511
+
512
+ "cache control" can {
513
+ "be undefined" in new BasicSetup {
514
+ setLocalFile("index.html")
515
+ push()
516
+ sentPutObjectRequest.getMetadata.getCacheControl must beNull
517
+ }
518
+ }
519
+
480
520
  "max_age in config" can {
481
521
  "be applied to all files" in new BasicSetup {
482
522
  config = "max_age: 60"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_website
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.6
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lauri Lehmijoki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-10 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor