From b950c4f1717ba69d80fb4c3bdf7ab1254635f52c Mon Sep 17 00:00:00 2001 From: Marcelo Dominguez Date: Fri, 8 Mar 2013 13:59:12 -0200 Subject: [PATCH] Set max-age header to Amazon S3 resources --- Changelog.md | 1 + config/defaults.yml | 1 + config/diaspora.yml.example | 4 ++++ config/initializers/carrierwave.rb | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/Changelog.md b/Changelog.md index 89409a31f..5c48bd8bb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ ## Refactor +* Add a configuration entry to set max-age header to Amazon S3 resources. [#4048](https://github.com/diaspora/diaspora/pull/4048) * Refactor people_controller#show and photos_controller#index [#4002](https://github.com/diaspora/diaspora/issues/4002) ## Features diff --git a/config/defaults.yml b/config/defaults.yml index 9d311cec4..19525e6fd 100644 --- a/config/defaults.yml +++ b/config/defaults.yml @@ -18,6 +18,7 @@ defaults: secret: bucket: region: + cache: true image_redirect_url: assets: serve: false diff --git a/config/diaspora.yml.example b/config/diaspora.yml.example index ec54a5070..e3c5177a0 100644 --- a/config/diaspora.yml.example +++ b/config/diaspora.yml.example @@ -75,6 +75,10 @@ configuration: ## Section #secret: 'changeme' #bucket: 'my_photos' #region: 'us-east-1' + + # Use max-age header on Amazon S3 resources. + # this would set a max-age value of 1 year + #cache : true ## Related to S3 you can set a url to redirect all requests to uploaded ## images to another host. If you for example set diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index 9782335ef..b86e52528 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -14,6 +14,10 @@ CarrierWave.configure do |config| :aws_secret_access_key => AppConfig.environment.s3.secret.get, :region => AppConfig.environment.s3.region.get } + if AppConfig.environment.s3.cache? + config.fog_attributes['Cache-Control'] = 'max-age=31536000' + end + config.fog_directory = AppConfig.environment.s3.bucket.get else config.storage = :file