ensure you're actually working with real lines, not assuming the return value is an array you can mutate, fixes #6

This commit is contained in:
John Bintz 2012-03-02 09:25:48 -05:00
parent e223e1ddbf
commit 00a9eb9062
2 changed files with 11 additions and 2 deletions

View File

@ -5,10 +5,13 @@ require 'rack/livereload'
use Rack::Logger use Rack::Logger
use Rack::LiveReload use Rack::LiveReload
run Rack::Directory.new('.')
if false
get '/' do get '/' do
File.read('index.html') File.read('index.html')
end end
run Sinatra::Application run Sinatra::Application
end

View File

@ -49,10 +49,14 @@ module Rack
else else
status, headers, body = @app.call(env) status, headers, body = @app.call(env)
new_body = body.dup
if !ignored?(env['PATH_INFO']) && !bad_browser?(env['HTTP_USER_AGENT']) if !ignored?(env['PATH_INFO']) && !bad_browser?(env['HTTP_USER_AGENT'])
if headers['Content-Type'][%r{text/html}] if headers['Content-Type'][%r{text/html}]
content_length = 0 content_length = 0
new_body = []
body.each do |line| body.each do |line|
if !headers['X-Rack-LiveReload'] && line['</head>'] if !headers['X-Rack-LiveReload'] && line['</head>']
host_to_use = (@options[:host] || env['HTTP_HOST'] || 'localhost').gsub(%r{:.*}, '') host_to_use = (@options[:host] || env['HTTP_HOST'] || 'localhost').gsub(%r{:.*}, '')
@ -75,13 +79,15 @@ module Rack
end end
content_length += line.length content_length += line.length
new_body << line
end end
headers['Content-Length'] = content_length.to_s headers['Content-Length'] = content_length.to_s
end end
end end
[ status, headers, body ] [ status, headers, new_body ]
end end
end end