Sha256: e2b739204894f9400a3b72e9e7877bf8a422a5f6d968d9cb637fd58daadd04af

Contents?: true

Size: 725 Bytes

Versions: 15

Compression:

Stored size: 725 Bytes

Contents

module Timber
  module RackMiddlewares
    # Reponsible for adding the HTTP context for applications that use `Rack`.
    class HTTPContext
      def initialize(app)
        @app = app
      end

      def call(env)
        request = ::Rack::Request.new(env)
        context = Contexts::HTTP.new(
          method: request.request_method,
          path: request.path,
          remote_addr: request.ip,
          request_id: request_id(env)
        )
        CurrentContext.with(context) do
          @app.call(env)
        end
      end

      private
        def request_id(env)
          env["X-Request-ID"] ||
            env["X-Request-Id"] ||
            env["action_dispatch.request_id"]
        end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
timber-1.1.14 lib/timber/rack_middlewares/http_context.rb
timber-1.1.13 lib/timber/rack_middlewares/http_context.rb
timber-1.1.12 lib/timber/rack_middlewares/http_context.rb
timber-1.1.11 lib/timber/rack_middlewares/http_context.rb
timber-1.1.10 lib/timber/rack_middlewares/http_context.rb
timber-1.1.9 lib/timber/rack_middlewares/http_context.rb
timber-1.1.8 lib/timber/rack_middlewares/http_context.rb
timber-1.1.7 lib/timber/rack_middlewares/http_context.rb
timber-1.1.6 lib/timber/rack_middlewares/http_context.rb
timber-1.1.5 lib/timber/rack_middlewares/http_context.rb
timber-1.1.4 lib/timber/rack_middlewares/http_context.rb
timber-1.1.3 lib/timber/rack_middlewares/http_context.rb
timber-1.1.2 lib/timber/rack_middlewares/http_context.rb
timber-1.1.1 lib/timber/rack_middlewares/http_context.rb
timber-1.1.0 lib/timber/rack_middlewares/http_context.rb