Class: Shift::Api::Core::Middleware::CustomHeaders

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/shift/api/core/middleware/custom_headers.rb

Overview

Faraday middleware to add extra headers to the request

Instance Method Summary collapse

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, options = {})
  self.app = app
  self.headers = options.fetch(:headers)
end

Instance Method Details

#call(env) ⇒ Object

Adds the custom headers to the passed in environment

Parameters:

  • env (Faraday::Env)

    The environment from faraday



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