Class: Shift::Api::Core::Middleware::CustomHeaders
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Shift::Api::Core::Middleware::CustomHeaders
- Defined in:
- lib/shift/api/core/middleware/custom_headers.rb
Overview
Faraday middleware to add extra headers to the request
Instance Method Summary collapse
-
#call(env) ⇒ Object
Adds the custom headers to the passed in environment.
-
#initialize(app, options = {}) ⇒ CustomHeaders
constructor
A new instance of CustomHeaders.
Constructor Details
#initialize(app, options = {}) ⇒ CustomHeaders
Returns a new instance of CustomHeaders.
9 10 11 12 |
# File 'lib/shift/api/core/middleware/custom_headers.rb', line 9 def initialize(app, = {}) self.app = app self.headers = .fetch(:headers) end |
Instance Method Details
#call(env) ⇒ Object
Adds the custom headers to the passed in environment
16 17 18 19 20 21 |
# File 'lib/shift/api/core/middleware/custom_headers.rb', line 16 def call(env) extra_headers = headers extra_headers = headers.call(env) if headers.respond_to?(:call) env.request_headers.merge!(extra_headers) app.call(env) end |