diff options
| author | Zog | 2018-02-26 16:45:00 +0100 | 
|---|---|---|
| committer | Zog | 2018-02-26 16:45:00 +0100 | 
| commit | ac9495472164136dd4604f89c7bebaee3cecdd0c (patch) | |
| tree | 6e4f7976d5ad4509792daa9c855f8b1494fb061f /config/middlewares | |
| parent | 206bf218e1b84dbe53683ec2e3f983cd30f7ded1 (diff) | |
| download | chouette-core-ac9495472164136dd4604f89c7bebaee3cecdd0c.tar.bz2 | |
Refs #5896; Add cahe-related headers for assets
Diffstat (limited to 'config/middlewares')
| -rw-r--r-- | config/middlewares/cachesettings.rb | 20 | 
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 | 
