From 6501c039b23ffa4b33ce1200edc320512d444cea Mon Sep 17 00:00:00 2001 From: Enric Lluelles Date: Mon, 23 Jan 2012 19:42:25 +0100 Subject: [PATCH 1/4] Content-Length is supposed to be bytes, not chars --- lib/rack/livereload.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rack/livereload.rb b/lib/rack/livereload.rb index 6945505..bfba052 100644 --- a/lib/rack/livereload.rb +++ b/lib/rack/livereload.rb @@ -74,7 +74,7 @@ module Rack headers["X-Rack-LiveReload"] = '1' end - content_length += line.length + content_length += line.bytesize end headers['Content-Length'] = content_length.to_s From ab4e7256bb3899d9fd950e26215ddc27a8331b8d Mon Sep 17 00:00:00 2001 From: Enric Lluelles Date: Mon, 23 Jan 2012 20:51:08 +0100 Subject: [PATCH 2/4] Added failing test --- spec/rack/livereload_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/rack/livereload_spec.rb b/spec/rack/livereload_spec.rb index 96d1cba..12fd1b9 100644 --- a/spec/rack/livereload_spec.rb +++ b/spec/rack/livereload_spec.rb @@ -53,6 +53,18 @@ describe Rack::LiveReload do end end + context 'unknown Content-Type' do + let(:ret) { [ 200, {}, [ 'hey ho' ] ] } + + before do + app.stubs(:call).with(env).returns(ret) + end + + it 'should not break' do + middleware.call(env).should_not raise_error(NoMethodError, /You have a nil object/) + end + end + context 'text/html' do before do app.stubs(:call).with(env).returns([ 200, { 'Content-Type' => 'text/html', 'Content-Length' => 0 }, [ '' ] ]) From 90b9a75b35bea38967734b7ac56b21b5b5caf746 Mon Sep 17 00:00:00 2001 From: Enric Lluelles Date: Mon, 23 Jan 2012 20:51:59 +0100 Subject: [PATCH 3/4] Check that the content-type header is there first --- lib/rack/livereload.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rack/livereload.rb b/lib/rack/livereload.rb index bfba052..3de003d 100644 --- a/lib/rack/livereload.rb +++ b/lib/rack/livereload.rb @@ -50,7 +50,7 @@ module Rack status, headers, body = @app.call(env) if !ignored?(env['PATH_INFO']) && !bad_browser?(env['HTTP_USER_AGENT']) - if headers['Content-Type'][%r{text/html}] + if headers['Content-Type'] && headers['Content-Type'][%r{text/html}] content_length = 0 body.each do |line| From 4caf4d9263115d03270515385f2d37c79ac9ac08 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 24 Jan 2012 08:55:43 -0500 Subject: [PATCH 4/4] bump version for release --- lib/rack-livereload.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rack-livereload.rb b/lib/rack-livereload.rb index d3b9213..d3a6d6d 100644 --- a/lib/rack-livereload.rb +++ b/lib/rack-livereload.rb @@ -1,6 +1,6 @@ require "rack/livereload" class Rack::LiveReload - VERSION = '0.3.3' + VERSION = '0.3.4' end