2013-04-23 20:28:23 +00:00
|
|
|
require 'rack/livereload'
|
|
|
|
|
|
|
|
module Rack
|
|
|
|
class LiveReload
|
|
|
|
class ProcessingSkipAnalyzer
|
|
|
|
BAD_USER_AGENTS = [ %r{MSIE} ]
|
|
|
|
|
|
|
|
def self.skip_processing?(result, env, options)
|
|
|
|
new(result, env, options).skip_processing?
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(result, env, options)
|
|
|
|
@env, @options = env, options
|
|
|
|
|
|
|
|
@status, @headers, @body = result
|
|
|
|
end
|
|
|
|
|
|
|
|
def skip_processing?
|
2013-08-20 20:55:47 +00:00
|
|
|
!html? || chunked? || inline? || ignored? || bad_browser? || !get?
|
2013-04-23 20:28:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def chunked?
|
|
|
|
@headers['Transfer-Encoding'] == 'chunked'
|
|
|
|
end
|
|
|
|
|
|
|
|
def inline?
|
|
|
|
@headers['Content-Disposition'] =~ %r{^inline}
|
|
|
|
end
|
|
|
|
|
|
|
|
def ignored?
|
|
|
|
@options[:ignore] and @options[:ignore].any? { |filter| @env['PATH_INFO'][filter] }
|
|
|
|
end
|
|
|
|
|
|
|
|
def bad_browser?
|
|
|
|
BAD_USER_AGENTS.any? { |pattern| @env['HTTP_USER_AGENT'] =~ pattern }
|
|
|
|
end
|
|
|
|
|
|
|
|
def html?
|
2013-05-13 16:43:23 +00:00
|
|
|
@headers['Content-Type'] =~ %r{text/html}
|
2013-04-23 20:28:23 +00:00
|
|
|
end
|
2013-08-20 20:55:47 +00:00
|
|
|
|
|
|
|
def get?
|
|
|
|
@env['REQUEST_METHOD'] == 'GET'
|
|
|
|
end
|
2013-04-23 20:28:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|