Sha256: 626cf8467a1b1176c0a5026b4b520fd524c70c99ed7ef53890d114f96be74de5

Contents?: true

Size: 924 Bytes

Versions: 73

Compression:

Stored size: 924 Bytes

Contents

module Faraday
  class Request::Authorization < Faraday::Middleware
    KEY = "Authorization".freeze unless defined? KEY

    # Public
    def self.header(type, token)
      case token
      when String, Symbol
        "#{type} #{token}"
      when Hash
        build_hash(type.to_s, token)
      else
        raise ArgumentError, "Can't build an Authorization #{type} header from #{token.inspect}"
      end
    end

    # Internal
    def self.build_hash(type, hash)
      comma = ", "
      values = []
      hash.each do |key, value|
        values << "#{key}=#{value.to_s.inspect}"
      end
      "#{type} #{values * comma}"
    end

    def initialize(app, type, token)
      @header_value = self.class.header(type, token)
      super(app)
    end

    # Public
    def call(env)
      unless env.request_headers[KEY]
        env.request_headers[KEY] = @header_value
      end
      @app.call(env)
    end
  end
end

Version data entries

73 entries across 65 versions & 6 rubygems

Version Path
faraday-0.17.6 lib/faraday/request/authorization.rb
faraday-0.17.5 lib/faraday/request/authorization.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/request/authorization.rb