Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

only halt execution in last_modified if status is currently 200 (to c…

…onfrom with RFC 2616)
  • Loading branch information...
commit f54f322b6576b6d9586a8d188679ecd7813b0c04 1 parent 48e1673
@rkh rkh authored
Showing with 18 additions and 1 deletion.
  1. +3 −0  CHANGES
  2. +1 −1  lib/sinatra/base.rb
  3. +14 −0 test/helpers_test.rb
View
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)
View
2  lib/sinatra/base.rb
@@ -356,7 +356,7 @@ def last_modified(time)
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
14 test/helpers_test.rb
@@ -858,6 +858,20 @@ def obj.is_a?(thing) 60.is_a?(thing) end
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
Please sign in to comment.
Something went wrong with that request. Please try again.