From 0ca84da6518a233a40ec0bf51da307691d91358c Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 17 Oct 2012 00:27:17 +0200 Subject: [PATCH 1/3] Bump travis-core --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5bb2406b..b0e8ff12 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,7 +40,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: 56ca16046cba99cc0b4cd0c520c6bb13ace9932a + revision: e12fd5e62181e62f9c4edb96fe0151f7f7b65f85 branch: sf-travis-api specs: travis-core (0.0.1) @@ -115,7 +115,7 @@ GEM atomic (1.0.1) avl_tree (1.1.3) backports (2.6.4) - builder (3.0.3) + builder (3.0.4) bunny (0.8.0) daemons (1.1.9) dalli (2.3.0) From 6252deadee28bedaedc51b625ef9e1321782306c Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 17 Oct 2012 18:51:11 +0200 Subject: [PATCH 2/3] improve caching headers --- lib/travis/api/app/extensions/scoping.rb | 13 ++++++++++++- lib/travis/api/app/responders/service.rb | 15 +++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/travis/api/app/extensions/scoping.rb b/lib/travis/api/app/extensions/scoping.rb index 96b76b83..72643ffe 100644 --- a/lib/travis/api/app/extensions/scoping.rb +++ b/lib/travis/api/app/extensions/scoping.rb @@ -3,6 +3,16 @@ require 'travis/api/app' class Travis::Api::App module Extensions module Scoping + module Helpers + def scope + env['travis.scope'].to_sym + end + + def public? + scope == :public + end + end + def self.registered(app) app.set default_scope: :public, anonymous_scopes: [:public] app.helpers(Helpers) @@ -16,8 +26,9 @@ class Travis::Api::App headers['X-Accepted-OAuth-Scopes'] = name.to_s if scopes.include? name + env['travis.scope'] = name headers['Vary'] = 'Accept' - headers['Vary'] << ', Authorization' if name == :public + headers['Vary'] << ', Authorization' unless public? true elsif env['travis.access_token'] halt 403, "insufficient access" diff --git a/lib/travis/api/app/responders/service.rb b/lib/travis/api/app/responders/service.rb index bd117e38..c0ed514f 100644 --- a/lib/travis/api/app/responders/service.rb +++ b/lib/travis/api/app/responders/service.rb @@ -14,12 +14,11 @@ module Travis::Api::App::Responders private def cache_control - if final? - endpoint.expires 31536000, :public # 1 year - elsif updated_at? - endpoint.cache_control :public, :must_revalidate - endpoint.last_modified resource.updated_at - end + mode = [endpoint.public? ? :public : :private] + mode << :must_revalidate unless final? + endpoint.expires(31536000, *mode) # 1 year + endpoint.etag resource.cache_key if cache_key? + endpoint.last_modified resource.updated_at if updated_at? end def final? @@ -30,6 +29,10 @@ module Travis::Api::App::Responders resource.respond_to?(:updated_at) && resource.updated_at end + def cache_key? + resource.respond_to?(:cache_key) && resource.cache_key + end + # Services potentially return all sorts of things # If it's a string, true or false we'll wrap it into a hash. # If it's an active record or scope we just pass so it can be processed by the json responder. From 720cbef577f8696d44aa8d8ebaa712606ee6b433 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 18 Oct 2012 23:49:15 +0200 Subject: [PATCH 3/3] allow underscore and dash in subdomains --- lib/travis/api/app/endpoint/authorization.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/travis/api/app/endpoint/authorization.rb b/lib/travis/api/app/endpoint/authorization.rb index e5c7d8aa..bd2919f3 100644 --- a/lib/travis/api/app/endpoint/authorization.rb +++ b/lib/travis/api/app/endpoint/authorization.rb @@ -223,8 +223,8 @@ class Travis::Api::App def target_ok?(target_origin) target_origin =~ %r{ - ^ http:// (localhost|127\.0\.0\.1)(:\d+)? $ | - ^ https:// (\w+\.)?travis-ci\.(org|com) $ + ^ http:// (localhost|127\.0\.0\.1)(:\d+)? $ | + ^ https:// ([\w-_]+\.)?travis-ci\.(org|com) $ }x end end