aboutsummaryrefslogtreecommitdiffstats
path: root/config/middlewares/cachesettings.rb
diff options
context:
space:
mode:
authorLuc Donnet2018-03-12 15:11:41 +0100
committerGitHub2018-03-12 15:11:41 +0100
commitfaa6c9b8a4262fb2c5212fd3b971337881bb242b (patch)
tree466cb4fd4bea3bd9aecb15a017b2ee27dfe32524 /config/middlewares/cachesettings.rb
parent10765f6378777d74b121faf9e6f2a17a9fb1594e (diff)
parentac9495472164136dd4604f89c7bebaee3cecdd0c (diff)
downloadchouette-core-faa6c9b8a4262fb2c5212fd3b971337881bb242b.tar.bz2
Merge pull request #344 from af83/5896-add-cache-headers
5896 Add cache-related headers for assets
Diffstat (limited to 'config/middlewares/cachesettings.rb')
-rw-r--r--config/middlewares/cachesettings.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/config/middlewares/cachesettings.rb b/config/middlewares/cachesettings.rb
new file mode 100644
index 000000000..8a122891f
--- /dev/null
+++ b/config/middlewares/cachesettings.rb
@@ -0,0 +1,20 @@
+class CacheSettings
+ def initialize app, pat
+ @app = app
+ @pat = pat
+ end
+
+ def call env
+ res = @app.call(env)
+ path = env["REQUEST_PATH"]
+ @pat.each do |pattern,data|
+ if path =~ pattern
+ res[1]["Cache-Control"] = data[:cache_control] if data.has_key?(:cache_control)
+ res[1]["Expires"] = (Time.now + data[:expires]).utc.rfc2822 if data.has_key?(:expires)
+ res[1]["X-Custom-Cache-Control"] = "yes" if Rails.env.development?
+ return res
+ end
+ end
+ res
+ end
+end