Class: Rack::UserAgent::Filter

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Filter.



8
9
10
11
12
13
# File 'lib/rack/user_agent/filter.rb', line 8

def initialize(app, browsers = [], options = {})
  @app                = app
  @browsers           = browsers
  @template           = options[:template]
  @force_with_cookie  = options[:force_with_cookie]
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/rack/user_agent/filter.rb', line 15

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