Class: Hawkins::Commands::LiveServe::SkipAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/hawkins/servlet.rb

Constant Summary collapse

BAD_USER_AGENTS =
[%r{MSIE}].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(req, res, options) ⇒ SkipAnalyzer

Returns a new instance of SkipAnalyzer.



14
15
16
17
18
# File 'lib/hawkins/servlet.rb', line 14

def initialize(req, res, options)
  @options = options
  @req = req
  @res = res
end

Class Method Details

.skip_processing?(req, res, options) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/hawkins/servlet.rb', line 10

def self.skip_processing?(req, res, options)
  new(req, res, options).skip_processing?
end

Instance Method Details

#bad_browser?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/hawkins/servlet.rb', line 32

def bad_browser?
  BAD_USER_AGENTS.any? { |pattern| @req['User-Agent'] =~ pattern }
end

#chunked?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/hawkins/servlet.rb', line 24

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

#html?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/hawkins/servlet.rb', line 36

def html?
  @res['Content-Type'] =~ %r{text/html}
end

#inline?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/hawkins/servlet.rb', line 28

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

#skip_processing?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/hawkins/servlet.rb', line 20

def skip_processing?
  !html? || chunked? || inline? || bad_browser?
end