don't try to close text/event-stream bodies, should fix #24

This commit is contained in:
John Bintz 2013-01-24 10:22:54 -05:00
parent fbbea710d7
commit 85855cb25a
3 changed files with 20 additions and 2 deletions

View File

@ -1,6 +1,6 @@
require "rack/livereload"
class Rack::LiveReload
VERSION = '0.3.10'
VERSION = '0.3.11'
end

View File

@ -52,7 +52,10 @@ module Rack
if path == '__rack' && ::File.file?(target = ::File.expand_path("../../../js/#{file}", __FILE__))
deliver_file(target)
else
status, headers, body = @app.call(env)
status, headers, body = result = @app.call(env)
return result if headers['Content-Type'] and headers['Content-Type']['text/event-stream']
body.close if body.respond_to?(:close)
new_body = [] ; body.each { |line| new_body << line.to_s }

View File

@ -54,6 +54,21 @@ describe Rack::LiveReload do
end
end
context 'text/event-stram' do
let(:body) { [ '<head></head>' ] }
let(:ret) { [ 200, { 'Content-Type' => 'text/event-stream' }, body ] }
before do
app.stubs(:call).with(env).returns(ret)
body.expects(:close).never
body.stubs(:respond_to?).with(:close).returns(true)
end
it 'should pass through' do
middleware.call(env).should == ret
end
end
context 'unknown Content-Type' do
let(:ret) { [ 200, {}, [ 'hey ho' ] ] }