Sha256: 4c4614db512a931e2ab6ac0eaa6819eb2e4e2dc0d12cd339bb2bec925b5c2971

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

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?
        !html? || chunked? || inline? || ignored? || bad_browser? || !get?
      end

      def chunked?
        @headers['Transfer-Encoding'] == 'chunked'
      end

      def inline?
        @headers['Content-Disposition'] =~ %r{^inline}
      end

      def ignored?
        path = @env['QUERY_STRING'].empty? ? @env['PATH_INFO'] : "#{@env['PATH_INFO']}?#{@env['QUERY_STRING']}"
        @options[:ignore] and @options[:ignore].any? { |filter| path[filter] }
      end

      def bad_browser?
        BAD_USER_AGENTS.any? { |pattern| @env['HTTP_USER_AGENT'] =~ pattern }
      end

      def html?
        @headers['Content-Type'] =~ %r{text/html|application/xhtml\+xml}
      end

      def get?
        @env['REQUEST_METHOD'] == 'GET'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-livereload-0.5.2 lib/rack/livereload/processing_skip_analyzer.rb