Sha256: add9b52172812686c14b869dfeeb36efd539f3ad8974cc1d8ad8ac7d1f8349ba

Contents?: true

Size: 1.01 KB

Versions: 20

Compression:

Stored size: 1.01 KB

Contents

begin
  require "rack"
rescue LoadError
end

if defined?(::Rack::Request)
  module Timber
    module Util
      class Request < ::Rack::Request
        def body_content
          content = body.read
          body.rewind
          content
        end

        def headers
          @headers ||= ::Hash[*@env.select {|k,v| k.start_with? 'HTTP_'}
            .collect {|k,v| [k.sub(/^HTTP_/, ''), v]}
            .collect {|k,v| [k.split('_').collect(&:capitalize).join('-'), v]}
            .sort
            .flatten]
        end

        def ip
          @ip ||= if @env["action_dispatch.remote_ip"]
            @env["action_dispatch.remote_ip"].to_s || super
          else
            super
          end
        end

        def referer
          # Rails 3.X returns "/" for some reason
          @referer ||= super == "/" ? nil : super
        end

        def request_id
          @request_id ||= @env["action_dispatch.request_id"] || @env["X-Request-ID"] ||
            @env["X-Request-Id"]
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
timber-2.0.21 lib/timber/util/request.rb
timber-2.0.20 lib/timber/util/request.rb
timber-2.0.19 lib/timber/util/request.rb
timber-2.0.17 lib/timber/util/request.rb
timber-2.0.16 lib/timber/util/request.rb
timber-2.0.15 lib/timber/util/request.rb
timber-2.0.14 lib/timber/util/request.rb
timber-2.0.12 lib/timber/util/request.rb
timber-2.0.11 lib/timber/util/request.rb
timber-2.0.10 lib/timber/util/request.rb
timber-2.0.9 lib/timber/util/request.rb
timber-2.0.8 lib/timber/util/request.rb
timber-2.0.7 lib/timber/util/request.rb
timber-2.0.6 lib/timber/util/request.rb
timber-2.0.5 lib/timber/util/request.rb
timber-2.0.4 lib/timber/util/request.rb
timber-2.0.3 lib/timber/util/request.rb
timber-2.0.2 lib/timber/util/request.rb
timber-2.0.1 lib/timber/util/request.rb
timber-2.0.0 lib/timber/util/request.rb