Sha256: f3332bfa89af35c8ff00f1c281a0f56d05b5ffa253c36b3790a3426b7346776f

Contents?: true

Size: 412 Bytes

Versions: 5

Compression:

Stored size: 412 Bytes

Contents

# frozen_string_literal: true

require 'securerandom'

# Captures request id
class RequestId
  def initialize(app)
    @app = app
  end

  def call(env)
    env['request_id'] = env['HTTP_X_REQUEST_ID'] || new_request_id
    status, headers, body = @app.call(env)
    headers['X-Request-Id'] ||= env['request_id']
    [status, headers, body]
  end

  private

  def new_request_id
    SecureRandom.uuid
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sensible_logging-0.4.8 lib/sensible_logging/middlewares/request_id.rb
sensible_logging-0.4.7 lib/sensible_logging/middlewares/request_id.rb
sensible_logging-0.4.3 lib/sensible_logging/middlewares/request_id.rb
sensible_logging-0.4.2 lib/sensible_logging/middlewares/request_id.rb
sensible_logging-0.4.1 lib/sensible_logging/middlewares/request_id.rb