last_modified ignores nil

This commit is contained in:
Simon Rozet 2010-03-04 03:29:55 -08:00
parent 035fe4705d
commit 3ff226272a
2 changed files with 10 additions and 0 deletions

View File

@ -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

View File

@ -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