Do not fail without content type #5

Merged
enriclluelles merged 2 commits from do_not_fail_without_content_type into master 2012-01-23 23:13:12 +00:00
2 changed files with 13 additions and 1 deletions

View File

@ -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|

View File

@ -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 }, [ '<head></head>' ] ])