diff --git a/config.ru b/config.ru index 836fb56..2fd24e8 100644 --- a/config.ru +++ b/config.ru @@ -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 diff --git a/lib/rack/livereload.rb b/lib/rack/livereload.rb index 6945505..c5fac35 100644 --- a/lib/rack/livereload.rb +++ b/lib/rack/livereload.rb @@ -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[''] 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