diff --git a/lib/travis/web/api_redirect.rb b/lib/travis/web/api_redirect.rb index 35361482..b13ef777 100644 --- a/lib/travis/web/api_redirect.rb +++ b/lib/travis/web/api_redirect.rb @@ -4,18 +4,6 @@ class Travis::Web::ApiRedirect < Sinatra::Base disable :protection, :static set api_endpoint: 'https://api.travis-ci.org' - set :api_types, %w[ - application/vnd.travis-ci.1+json - application/vnd.travis-ci.1+xml - application/vnd.travis-ci.1+png - application/xml - application/json - ] - - set :frontend_types, %w[ - text/html application/xhtml+xml - ] - get '/:owner_name/:name.png' do redirect! end @@ -24,26 +12,8 @@ class Travis::Web::ApiRedirect < Sinatra::Base redirect! end - get '/:owner_name/:name/builds.json' do - redirect! "/repos#{request.fullpath}" - end - - after do - redirect! if catch_all? and api_call? - end - private - def catch_all? - headers['Content-Location'] == '/' and request.path_info != '/' - end - - def api_call? - return true if request.accept.empty? or env['HTTP_ACCEPT'] == '*/*' - preferred = request.preferred_type(*settings.frontend_types, *settings.api_types) - settings.api_types.include? preferred - end - def redirect!(path = nil) path = File.join(settings.api_endpoint, path || request.fullpath) redirect(path, 301) diff --git a/spec/api_redirect_spec.rb b/spec/api_redirect_spec.rb index 9e121083..bc8e2a9a 100644 --- a/spec/api_redirect_spec.rb +++ b/spec/api_redirect_spec.rb @@ -10,30 +10,4 @@ describe Travis::Web::ApiRedirect do it 'redirects /:owner/:repo.png' do get('/foo/bar.png').should be_redirect end - - it 'does not redirect catch-all for browsers' do - get('/foo/bar', {}, 'HTTP_ACCEPT' => browser_accept).should_not be_redirect - end - - it 'does not redirect catch-all with generic Accept header' do - get('/foo/bar', {}, 'HTTP_ACCEPT' => '*/*').should be_redirect - end - - it 'redirects catch-all without Accept header' do - get('/foo/bar').should be_redirect - end - - it 'redirects catch-all JSON requests' do - get('/foo/bar', {}, 'HTTP_ACCEPT' => 'application/json').should be_redirect - end - - it 'does not redirect asset requests' do - get('/version').should_not be_redirect - end - - it 'redirects /:owner_name/:name/builds.json' do - response = get('/foo/bar/builds.json') - response.should be_redirect - response.headers['Location'].should == 'https://api.travis-ci.org/repos/foo/bar/builds.json' - end end