Skip to content

Commit

Permalink
Add a redirect option
Browse files Browse the repository at this point in the history
  • Loading branch information
joren committed Mar 1, 2010
1 parent 0323a95 commit f5248ef
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rack-mobile-detect.rb
Expand Up @@ -121,6 +121,8 @@ def initialize(app, options = {})
'240x320|320x320|mobileexplorer|j2me|sgh|portable|sprint|vodafone|' +
'docomo|kddi|softbank|pdxgw|j-phone|astel|minimo|plucker|netfront|' +
'xiino|mot-v|mot-e|portalmmm|sagem|sie-s|sie-m|android|ipod', true)

@redirect_to = options[:redirect_to]
end

# Because the web app may be multithreaded, this method must
Expand All @@ -142,7 +144,10 @@ def call(env)
# Fall back on catch-all User-Agent regex
device ||= Regexp.new(@regex_ua_catchall).match(user_agent) != nil

env[X_HEADER] = device.to_s if device
if device
env[X_HEADER] = device.to_s
return [301, {'Location' => @redirect_to}, []] if @redirect_to
end

@app.call(env)
end
Expand Down

0 comments on commit f5248ef

Please sign in to comment.