Skip to content

Commit

Permalink
Handle conditional get in live requests - this will prevent error whe…
Browse files Browse the repository at this point in the history
…n using stale on live streams(issue rails#9636)
  • Loading branch information
imanel committed Mar 14, 2013
1 parent 36f7732 commit 2651b59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions actionpack/lib/action_controller/metal/live.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions actionpack/test/controller/live_stream_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 2651b59

Please sign in to comment.