Class: Faraday::Request::Authorization

Inherits:
Middleware
  • Object
show all
Defined in:
lib/faraday/request/authorization.rb

Overview

Request middleware for the Authorization HTTP header

Constant Summary collapse

KEY =
'Authorization'

Constants inherited from Middleware

Middleware::DEFAULT_OPTIONS, Middleware::LOCK

Instance Attribute Summary

Attributes inherited from Middleware

#app, #options

Instance Method Summary collapse

Methods inherited from Middleware

#call, #close, default_options, default_options=

Methods included from MiddlewareRegistry

#lookup_middleware, #register_middleware, #registered_middleware, #unregister_middleware

Constructor Details

#initialize(app, type, *params) ⇒ Authorization

Returns a new instance of Authorization.

Parameters:

  • app (#call)
  • type (String, Symbol)

    Type of Authorization

  • params (Array<String, Proc, #call>)

    parameters to build the Authorization header. If the type is ‘:basic`, then these can be a login and password pair. Otherwise, a single value is expected that will be appended after the type. This value can be a proc or an object responding to `.call`, in which case it will be invoked on each request.



16
17
18
19
20
# File 'lib/faraday/request/authorization.rb', line 16

def initialize(app, type, *params)
  @type = type
  @params = params
  super(app)
end

Instance Method Details

#on_request(env) ⇒ Object

Parameters:



23
24
25
26
27
# File 'lib/faraday/request/authorization.rb', line 23

def on_request(env)
  return if env.request_headers[KEY]

  env.request_headers[KEY] = header_from(@type, env, *@params)
end