class SmartProxyDynflowCore::RequestIdMiddleware

Public Class Methods

new(app) click to toggle source
# File lib/smart_proxy_dynflow_core/request_id_middleware.rb, line 3
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/smart_proxy_dynflow_core/request_id_middleware.rb, line 7
def call(env)
  ::Logging.mdc['remote_ip'] = env['REMOTE_ADDR']
  if env.has_key?('HTTP_X_REQUEST_ID')
    ::Logging.mdc['request'] = env['HTTP_X_REQUEST_ID']
  else
    ::Logging.mdc['request'] = SecureRandom.uuid
  end
  status, header, body = @app.call(env)
  [status, header, ::Rack::BodyProxy.new(body) { ::Logging.mdc.clear }]
end