stream body munging

This commit is contained in:
John Bintz 2011-11-07 08:41:51 -05:00
parent 66e584e37a
commit fde86b211b

View File

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