stream body munging
This commit is contained in:
parent
66e584e37a
commit
fde86b211b
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue