Guest User

Untitled

a guest
Feb 21st, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. # use with::
  2. #
  3. # use CacheSettings, {
  4. # /\/static\// =>
  5. # { :cache_control => "max-age=86400, public",
  6. # :expires => 86400
  7. # }
  8. # }
  9. # use Rack::Static, :urls => ["/static"] # for example
  10.  
  11. class CacheSettings
  12. def initialize app, pat
  13. @app = app
  14. @pat = pat
  15. end
  16. def call env
  17. res = @app.call(env)
  18. path = env["REQUEST_PATH"]
  19. @pat.each do |pattern,data|
  20. if path =~ pattern
  21. res[1]["Cache-Control"] = data[:cache_control] if data.has_key?(:cache_control)
  22. res[1]["Expires"] = (Time.now + data[:expires]).utc.rfc2822 if data.has_key?(:expires)
  23. return res
  24. end
  25. end
  26. res
  27. end
  28. end
Add Comment
Please, Sign In to add comment