stream body munging

This commit is contained in:
John Bintz 2011-11-07 08:41:51 -05:00
parent 66e584e37a
commit fde86b211b
1 changed files with 3 additions and 5 deletions

View File

@ -16,20 +16,18 @@ module Rack
case headers['Content-Type']
when %r{text/html}
new_body = []
body.each do |line|
if line['</head>']
src = LIVERELOAD_JS_PATH.dup
src << "?host=#{env['HTTP_HOST'].gsub(%r{:.*}, '')}" if env['HTTP_HOST']
line.gsub!('</head>', %{<script type="text/javascript" src="#{src}"></script></head>})
end
new_body << line
headers["X-Rack-LiveReload"] = '1'
break
end
end
body = new_body
headers['Content-Length'] = body.join.length.to_s
end