Skip to content

Commit

Permalink
Implement both Cache-Control and Last-Modified
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr committed Oct 4, 2010
1 parent 6df3b1a commit 6409155
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions timeless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 6409155

Please sign in to comment.