Class: Rack::UserAgent::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/useragent/filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, required_browsers = [], options = {}) ⇒ Filter

Returns a new instance of Filter.



10
11
12
13
14
15
# File 'lib/rack/useragent/filter.rb', line 10

def initialize(app, required_browsers = [], options = {})
  @app                = app
  @browsers           = required_browsers.map{ |b| OpenStruct.new(:browser => b[0], :version => b[1]) }
  @template           = options[:template]
  @force_with_cookie  = options[:force_with_cookie]
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/rack/useragent/filter.rb', line 17

def call(env)
  request = Rack::Request.new(env)
  useragent = ::UserAgent.parse(env["HTTP_USER_AGENT"].to_s)
  if useragent.any? && !detection_disabled_by_cookie?(request.cookies) && unsupported?(useragent)
    content = render_page(useragent)
    [200, {"Content-Type" => "text/html", "Content-Length" => content.length.to_s}, content]
  else
    @app.call(env)
  end
end