Permalink
Browse files

Merge pull request #9713 from imanel/live_stale

Handle conditional get in live requests
  • Loading branch information...
2 parents 36f7732 + 2651b59 commit b7b6c22d7807c7f587dcde90ea30f98f17278d1a @tenderlove tenderlove committed Mar 14, 2013
Showing with 19 additions and 0 deletions.
  1. +4 −0 actionpack/lib/action_controller/metal/live.rb
  2. +15 −0 actionpack/test/controller/live_stream_test.rb
@@ -98,6 +98,10 @@ def build_buffer(response, body)
def merge_default_headers(original, default)
Header.new self, super
end
+
+ def handle_conditional_get!
+ super unless committed?
+ end
end
def process(name)
@@ -48,6 +48,10 @@ def thread_locals
end
response.stream.close
end
+
+ def with_stale
+ render :text => 'stale' if stale?(:etag => "123")
+ end
end
tests TestController
@@ -117,5 +121,16 @@ def test_render_text
assert_equal 'zomg', response.body
assert response.stream.closed?, 'stream should be closed'
end
+
+ def test_stale_without_etag
+ get :with_stale
+ assert_equal 200, @response.status.to_i
+ end
+
+ def test_stale_with_etag
+ @request.if_none_match = Digest::MD5.hexdigest("123")
+ get :with_stale
+ assert_equal 304, @response.status.to_i
+ end
end
end

0 comments on commit b7b6c22

Please sign in to comment.