Sha256: a4e46ef9ffbad58c91377dc5f6d7b4284a9571071e0e8bc03566208be3d45671

Contents?: true

Size: 658 Bytes

Versions: 6

Compression:

Stored size: 658 Bytes

Contents

require 'rest-core/middleware'

class RestCore::Oauth2Header
  def self.members; [:access_token]; end
  include RestCore::Middleware

  def call env
    start_time = Time.now
    headers = {'Authorization' => "OAuth #{access_token(env)}"}.
                merge(env[REQUEST_HEADERS] || {}) if access_token(env)

    event = Event::WithHeader.new(Time.now - start_time,
              "Authorization: #{headers['Authorization']}") if headers

    app.call(log(cache_key(
      env.merge(REQUEST_HEADERS => headers || env[REQUEST_HEADERS])), event))
  end

  def cache_key env
    env.merge('cache.key' => "#{request_uri(env)}&#{access_token(env)}")
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rest-core-0.7.2 lib/rest-core/middleware/oauth2_header.rb
rest-core-0.7.0 lib/rest-core/middleware/oauth2_header.rb
rest-core-0.4.0 lib/rest-core/middleware/oauth2_header.rb
rest-core-0.4.0.pre.2 lib/rest-core/middleware/oauth2_header.rb
rest-core-0.4.0.pre.1 lib/rest-core/middleware/oauth2_header.rb
rest-core-0.4.0.pre.0 lib/rest-core/middleware/oauth2_header.rb