Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Created October 11, 2009 23:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save juliocesar/207947 to your computer and use it in GitHub Desktop.
Save juliocesar/207947 to your computer and use it in GitHub Desktop.
module Rack
class NoIE
def initialize(app, options = {})
@app = app
@options = options
@options[:redirect] ||= 'http://www.microsoft.com/windows/internet-explorer/default.aspx'
@options[:minimum] ||= 7.0
end
def call(env)
ie_found_in?(env) ? kick_it : @app.call(env)
end
private
def ie_found_in?(env)
if env['HTTP_USER_AGENT']
is_ie?(env['HTTP_USER_AGENT']) and ie_version(env['HTTP_USER_AGENT']) < @options[:minimum] and @options[:redirect] != env['PATH_INFO']
end
end
def is_ie?(ua_string)
# We need at least one digit to be able to get the version, hence the \d
ua_string.match(/MSIE \d/) ? true : false
end
def ie_version(ua_string)
ua_string.match(/MSIE (\S+)/)[1].to_f
end
def kick_it
[301, {'Location' => @options[:redirect]}, 'Fail browser is fail']
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment