Class: Psc::Faraday::HttpBasic
- Inherits:
-
Object
- Object
- Psc::Faraday::HttpBasic
- Defined in:
- lib/psc/faraday/http_basic.rb
Overview
Faraday middleware that implements HTTP Basic. This is not
PSC-specific, and Faraday even includes HTTP Basic support, but
Faraday's support is not implemented as middleware. Using
middleware makes setting up a connection based on the
:authenticator
option cleaner.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Sets the
Authorization
request header using the HTTP Basic scheme. -
#initialize(app, username, password) ⇒ HttpBasic
constructor
Create an instance of the middleware.
Constructor Details
#initialize(app, username, password) ⇒ HttpBasic
Create an instance of the middleware.
21 22 23 24 |
# File 'lib/psc/faraday/http_basic.rb', line 21 def initialize(app, username, password) @app = app @header_value = "Basic #{Base64.encode64([username, password].join(':')).strip}" end |
Instance Method Details
#call(env) ⇒ Object
Sets the Authorization
request header using the HTTP Basic
scheme.
29 30 31 32 33 |
# File 'lib/psc/faraday/http_basic.rb', line 29 def call(env) env[:request_headers]['Authorization'] = @header_value @app.call(env) end |