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