Class: FlexCommerceApi::JsonApiClientExtension::CaptureSurrogateKeysMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/flex_commerce_api/json_api_client_extension/capture_surrogate_keys_middleware.rb

Instance Method Summary collapse

Instance Method Details

#call(environment) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/flex_commerce_api/json_api_client_extension/capture_surrogate_keys_middleware.rb', line 5

def call(environment)
  @app.call(environment).on_complete do |env|
    surrogate_keys = env.response_headers['external-surrogate-key'].split(' ') if env.response_headers['external-surrogate-key']

    if surrogate_keys && Thread.current[:shift_surrogate_keys]
      Thread.current[:shift_surrogate_keys].concat(surrogate_keys)
    end
  end
end