blob: 8a122891f65a94b4e229d55abd84ef8e12dacdb4 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
 |