Skip to content

Commit

Permalink
Merge pull request johnbintz#5 from enriclluelles/do_not_fail_without…
Browse files Browse the repository at this point in the history
…_content_type

Do not fail without content type
  • Loading branch information
johnbintz committed Jan 23, 2012
2 parents 9e75660 + 90b9a75 commit 1c030a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/livereload.rb
Expand Up @@ -50,7 +50,7 @@ def call(env)
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|
Expand Down
12 changes: 12 additions & 0 deletions spec/rack/livereload_spec.rb
Expand Up @@ -53,6 +53,18 @@
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 }, [ '<head></head>' ] ])
Expand Down

0 comments on commit 1c030a9

Please sign in to comment.