class Faraday::Request::Authorization

Request middleware for the Authorization HTTP header

def header_from(type, env, *params)

Returns:
  • (String) - a header value

Parameters:
  • params (Array) --
  • env (Faraday::Env) --
  • type (String, Symbol) --
def header_from(type, env, *params)
  if type.to_s.casecmp('basic').zero? && params.size == 2
    Utils.basic_header_from(*params)
  elsif params.size != 1
    raise ArgumentError, "Unexpected params received (got #{params.size} instead of 1)"
  else
    value = params.first
    if (value.is_a?(Proc) && value.arity == 1) || (value.respond_to?(:call) && value.method(:call).arity == 1)
      value = value.call(env)
    elsif value.is_a?(Proc) || value.respond_to?(:call)
      value = value.call
    end
    "#{type} #{value}"
  end
end

def initialize(app, type, *params)

Parameters:
  • params (Array) -- parameters to build the Authorization header.
  • type (String, Symbol) -- Type of Authorization
  • app (#call) --
def initialize(app, type, *params)
  @type = type
  @params = params
  super(app)
end

def on_request(env)

Parameters:
  • env (Faraday::Env) --
def on_request(env)
  return if env.request_headers[KEY]
  env.request_headers[KEY] = header_from(@type, env, *@params)
end