only halt execution in last_modified if status is currently 200 (to confrom with RFC 2616)

This commit is contained in:
Konstantin Haase 2011-09-17 14:42:38 -07:00
parent 48e167317e
commit f54f322b65
3 changed files with 18 additions and 1 deletions

View File

@ -82,6 +82,9 @@
* Conditional requests on `etag` helper now work properly for unsafe HTTP
methods. (Matthew Schinckel, Konstantin Haase)
* The `last_modified` helper does not stop execution and change the status code
if the status code is something different than 200. (Konstantin Haase)
* `Sinatra::Base.run!` now prints to stderr rather than stdout. (Andrew
Armenia)

View File

@ -356,7 +356,7 @@ module Sinatra
time = time_for time
response['Last-Modified'] = time.httpdate
unless env['HTTP_IF_NONE_MATCH']
if status == 200 and not env['HTTP_IF_NONE_MATCH']
# compare based on seconds since epoch
since = Time.httpdate(env['HTTP_IF_MODIFIED_SINCE']).to_i
halt 304 if since >= time.to_i

View File

@ -858,6 +858,20 @@ class HelpersTest < Test::Unit::TestCase
assert ! response['Last-Modified']
end
it 'does not change a status other than 200' do
mock_app do
get '/' do
status 299
last_modified Time.at(0)
'ok'
end
end
get('/', {}, 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 26 Sep 2030 23:43:52 GMT')
assert_status 299
assert_body 'ok'
end
[Time.now, DateTime.now, Date.today, Time.now.to_i,
Struct.new(:to_time).new(Time.now) ].each do |last_modified_time|
describe "with #{last_modified_time.class.name}" do