Class: FixMicrosoftLinks::Rack::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/fix_microsoft_links.rb

Constant Summary collapse

USER_AGENTS_REGEX =
/[^\w](Word|Excel|PowerPoint|ms-office)([^\w]|\z)/

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Response



6
7
8
# File 'lib/fix_microsoft_links.rb', line 6

def initialize(app)  
  @app = app  
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/fix_microsoft_links.rb', line 10

def call(env)
  # Clicking a URL from Microsoft apps will redirect you to login to already authenticated sites otherwise :(
  # http://support.microsoft.com/kb/899927
  if env["HTTP_USER_AGENT"] =~ USER_AGENTS_REGEX
    body = StringIO.new("<html><head><meta http-equiv='refresh' content='0'/></head><body></body></html>")
    return [200, {"Content-Type" => "text/html"}, body]
  end
  @app.call(env)
end