only halt execution in last_modified if status is currently 200 (to confrom with RFC 2616)
This commit is contained in:
parent
48e167317e
commit
f54f322b65
3
CHANGES
3
CHANGES
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue