From 88c5bae9fc11e67997963d0daa11ffec70a1373c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 31 Oct 2013 16:07:19 +0100 Subject: [PATCH] Don't redirect to api if we want something from images dir --- lib/travis/web/api_redirect.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/travis/web/api_redirect.rb b/lib/travis/web/api_redirect.rb index b13ef777..5bf8a688 100644 --- a/lib/travis/web/api_redirect.rb +++ b/lib/travis/web/api_redirect.rb @@ -4,7 +4,21 @@ class Travis::Web::ApiRedirect < Sinatra::Base disable :protection, :static set api_endpoint: 'https://api.travis-ci.org' - get '/:owner_name/:name.png' do + class NotPublicImages + Match = Struct.new(:captures) + + def initialize(pattern, except) + @except = except + @pattern = pattern + @captures = Match.new([]) + end + + def match(str) + @captures if str =~ @pattern && str !~ @except + end + end + + get NotPublicImages.new(%r{^/(\w+)/(\w+).png}, %r{^/images/}) do redirect! end @@ -14,6 +28,10 @@ class Travis::Web::ApiRedirect < Sinatra::Base private + def public_image? + params[:owner_name] == 'images' + end + def redirect!(path = nil) path = File.join(settings.api_endpoint, path || request.fullpath) redirect(path, 301)