From 85855cb25a428c6c39fec72e29884744a45fea91 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 24 Jan 2013 10:22:54 -0500 Subject: [PATCH] don't try to close text/event-stream bodies, should fix #24 --- lib/rack-livereload.rb | 2 +- lib/rack/livereload.rb | 5 ++++- spec/rack/livereload_spec.rb | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/rack-livereload.rb b/lib/rack-livereload.rb index aee0d6e..bb21d56 100644 --- a/lib/rack-livereload.rb +++ b/lib/rack-livereload.rb @@ -1,6 +1,6 @@ require "rack/livereload" class Rack::LiveReload - VERSION = '0.3.10' + VERSION = '0.3.11' end diff --git a/lib/rack/livereload.rb b/lib/rack/livereload.rb index bec1bf9..c5964c3 100644 --- a/lib/rack/livereload.rb +++ b/lib/rack/livereload.rb @@ -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 } diff --git a/spec/rack/livereload_spec.rb b/spec/rack/livereload_spec.rb index 649a9e6..fa39e2c 100644 --- a/spec/rack/livereload_spec.rb +++ b/spec/rack/livereload_spec.rb @@ -54,6 +54,21 @@ describe Rack::LiveReload do end end + context 'text/event-stram' do + let(:body) { [ '' ] } + 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' ] ] }