Use Rack::Request#user_agent
This commit is contained in:
parent
7ad4ed1109
commit
973bd38f66
|
@ -2,7 +2,7 @@ class Travis::Web::App::MobileRedirect < Struct.new(:app)
|
||||||
def call(env)
|
def call(env)
|
||||||
request = Rack::Request.new env
|
request = Rack::Request.new env
|
||||||
|
|
||||||
if request.params['mobile'] || env['HTTP_AGENT'] =~ /Mobile|webOS/
|
if request.params['mobile'] || request.user_agent.to_s =~ /Mobile|webOS/
|
||||||
location = 'https://secure.travis-ci.org' + request.fullpath
|
location = 'https://secure.travis-ci.org' + request.fullpath
|
||||||
[301, { 'Content-Type' => 'text/plain', 'Location' => location }, []]
|
[301, { 'Content-Type' => 'text/plain', 'Location' => location }, []]
|
||||||
else
|
else
|
||||||
|
|
|
@ -6,7 +6,7 @@ describe Travis::Web::App::MobileRedirect do
|
||||||
let(:agent) { 'blah blah Mobile blablah' }
|
let(:agent) { 'blah blah Mobile blablah' }
|
||||||
|
|
||||||
it 'redirects to secure.travis-ci.org' do
|
it 'redirects to secure.travis-ci.org' do
|
||||||
get('/foo/bar?baz', {}, 'HTTP_AGENT' => agent).should be_redirect
|
get('/foo/bar?baz', {}, 'HTTP_USER_AGENT' => agent).should be_redirect
|
||||||
last_response.headers['Location'].should == 'https://secure.travis-ci.org/foo/bar?baz'
|
last_response.headers['Location'].should == 'https://secure.travis-ci.org/foo/bar?baz'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user