Permalink
Browse files

Implement both Cache-Control and Last-Modified

  • Loading branch information...
1 parent 6df3b1a commit 64091550ce3ee70fdd52f8718e92c7a75de6fe13 @judofyr committed Oct 4, 2010
Showing with 10 additions and 0 deletions.
  1. +10 −0 timeless.rb
View
@@ -20,6 +20,7 @@ class NotFound < StandardError; end
module Timeless
set :views, File.dirname(__FILE__) + '/timeless/views'
set :dynamic_templates, true
+ set :last_modified, Time.now
set :haml, {
:format => :html5,
@@ -28,6 +29,15 @@ module Timeless
}
def service(*a)
+ if last = @env['HTTP_LAST_MODIFIED_SINCE'] and
+ Time.parse(last).to_i >= Timeless.options[:last_modified].to_i
+
+ @status = 304
+ @body = []
+ return self
+ end
+
+ @headers['Last-Modified'] = Timeless.options[:last_modified].rfc2822
super
rescue NotFound
@status = 404

0 comments on commit 6409155

Please sign in to comment.