diff --git a/lib/rack/livereload.rb b/lib/rack/livereload.rb index 99efffb..c693d24 100644 --- a/lib/rack/livereload.rb +++ b/lib/rack/livereload.rb @@ -59,7 +59,9 @@ module Rack else status, headers, body = result = @app.call(env) - return result if headers['Content-Type'] and headers['Content-Type']['text/event-stream'] + if (headers['Content-Type'] and headers['Content-Type']['text/event-stream']) or headers['Transfer-Encoding'] == 'chunked' + return result + end body.close if body.respond_to?(:close) diff --git a/spec/rack/livereload_spec.rb b/spec/rack/livereload_spec.rb index bb897ab..b1488d6 100644 --- a/spec/rack/livereload_spec.rb +++ b/spec/rack/livereload_spec.rb @@ -79,6 +79,21 @@ describe Rack::LiveReload do end end + context 'chunked response' do + let(:body) { [ '' ] } + let(:ret) { [ 200, { 'Transfer-Encoding' => 'chunked' }, 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' ] ] }