Class: SmartProxyDynflowCore::RequestIdMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_proxy_dynflow_core/request_id_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RequestIdMiddleware

Returns a new instance of RequestIdMiddleware.



3
4
5
# File 'lib/smart_proxy_dynflow_core/request_id_middleware.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# 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