Class: Rack::UserAgent::Filter
- Inherits:
-
Object
- Object
- Rack::UserAgent::Filter
- Defined in:
- lib/rack/useragent/filter.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, required_browsers = [], options = {}) ⇒ Filter
constructor
A new instance of Filter.
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 = [], = {}) @app = app @browsers = required_browsers.map{ |b| OpenStruct.new(:browser => b[0], :version => b[1]) } @template = [:template] @force_with_cookie = [: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? && !(request.) && unsupported?(useragent) content = render_page(useragent) [200, {"Content-Type" => "text/html", "Content-Length" => content.length.to_s}, content] else @app.call(env) end end |