lib/middleware.rb in pakyow-assets-0.1.1 vs lib/middleware.rb in pakyow-assets-0.1.2
- old
+ new
@@ -1,5 +1,7 @@
+require 'time'
+
module Pakyow
module Assets
class Middleware
def initialize(app)
@app = app
@@ -19,13 +21,15 @@
headers = {
'Content-Type' => Rack::Mime.mime_type(File.extname(path))
}
- if Pakyow::Config.assets.cache
+ if Pakyow::Config.assets.cache && Pakyow::Assets.fingerprinted?(File.extname(path))
mtime = File.mtime(path)
headers['Age'] = (Time.now - mtime).to_i
headers['Cache-Control'] = 'public, max-age=31536000'
+ headers['Vary'] = 'Accept-Encoding'
+ headers['Last-Modified'] = mtime.httpdate
end
[200, headers, File.open(path)]
end
else