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.
12 13 14 15 16 17 18 |
# File 'lib/rack/useragent/filter.rb', line 12 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] @custom_message = [:custom_message] end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rack/useragent/filter.rb', line 20 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 |