Merge branch 'master' of github.com:travis-ci/travis-api

Conflicts:
	Gemfile.lock
This commit is contained in:
Sven Fuchs 2012-10-19 16:03:47 +02:00
commit 876564ca12
3 changed files with 23 additions and 9 deletions

View File

@ -224,7 +224,7 @@ class Travis::Api::App
def target_ok?(target_origin) def target_ok?(target_origin)
target_origin =~ %r{ target_origin =~ %r{
^ http:// (localhost|127\.0\.0\.1)(:\d+)? $ | ^ http:// (localhost|127\.0\.0\.1)(:\d+)? $ |
^ https:// (\w+\.)?travis-ci\.(org|com) $ ^ https:// ([\w-_]+\.)?travis-ci\.(org|com) $
}x }x
end end
end end

View File

@ -3,6 +3,16 @@ require 'travis/api/app'
class Travis::Api::App class Travis::Api::App
module Extensions module Extensions
module Scoping module Scoping
module Helpers
def scope
env['travis.scope'].to_sym
end
def public?
scope == :public
end
end
def self.registered(app) def self.registered(app)
app.set default_scope: :public, anonymous_scopes: [:public] app.set default_scope: :public, anonymous_scopes: [:public]
app.helpers(Helpers) app.helpers(Helpers)
@ -16,8 +26,9 @@ class Travis::Api::App
headers['X-Accepted-OAuth-Scopes'] = name.to_s headers['X-Accepted-OAuth-Scopes'] = name.to_s
if scopes.include? name if scopes.include? name
env['travis.scope'] = name
headers['Vary'] = 'Accept' headers['Vary'] = 'Accept'
headers['Vary'] << ', Authorization' if name == :public headers['Vary'] << ', Authorization' unless public?
true true
elsif env['travis.access_token'] elsif env['travis.access_token']
halt 403, "insufficient access" halt 403, "insufficient access"

View File

@ -14,12 +14,11 @@ module Travis::Api::App::Responders
private private
def cache_control def cache_control
if final? mode = [endpoint.public? ? :public : :private]
endpoint.expires 31536000, :public # 1 year mode << :must_revalidate unless final?
elsif updated_at? endpoint.expires(31536000, *mode) # 1 year
endpoint.cache_control :public, :must_revalidate endpoint.etag resource.cache_key if cache_key?
endpoint.last_modified resource.updated_at endpoint.last_modified resource.updated_at if updated_at?
end
end end
def final? def final?
@ -30,6 +29,10 @@ module Travis::Api::App::Responders
resource.respond_to?(:updated_at) && resource.updated_at resource.respond_to?(:updated_at) && resource.updated_at
end end
def cache_key?
resource.respond_to?(:cache_key) && resource.cache_key
end
# Services potentially return all sorts of things # 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 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. # If it's an active record or scope we just pass so it can be processed by the json responder.