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::LiveReload
run Rack::Directory.new('.')
if false
get '/' do
File.read('index.html')
end
run Sinatra::Application
end

View File

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