diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 406008f9..211dfefc 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -240,6 +240,7 @@ module Sinatra # matches the time specified, execution is immediately halted with a # '304 Not Modified' response. def last_modified(time) + return unless time time = time.to_time if time.respond_to?(:to_time) time = time.httpdate if time.respond_to?(:httpdate) response['Last-Modified'] = time diff --git a/test/helpers_test.rb b/test/helpers_test.rb index 7c8c0920..2671ec95 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -451,6 +451,15 @@ class HelpersTest < Test::Unit::TestCase assert_equal 304, status assert_equal '', body end + + it 'ignores nil' do + mock_app { + get '/' do last_modified nil; 200; end + } + + get '/' + assert ! response['Last-Modified'] + end end describe 'etag' do