class Logtail::Util::Request

@private

Constants

HTTP_HEADER_NEW_DELIMITER
HTTP_HEADER_ORIGINAL_DELIMITER

We store strings as constants since they are reused on a per request basis. This avoids string allocations.

HTTP_PREFIX
REMOTE_IP_KEY_NAME
REQUEST_ID_KEY_NAME1
REQUEST_ID_KEY_NAME2

Public Instance Methods

body_content() click to toggle source
# File lib/logtail-rack/util/request.rb, line 15
def body_content
  content = body.read
  body.rewind
  content
end
headers() click to toggle source

Returns a list of request headers. The rack env contains a lot of data, this function identifies those that were the actual request headers.

This was extracted from: github.com/ruby-grape/grape/blob/91c6c78ae3d3f3ffabaf57ffc4dc35ab7cfc7b5f/lib/grape/request.rb#L30

# File lib/logtail-rack/util/request.rb, line 25
def headers
  @headers ||= begin
    headers = {}

    @env.each_pair do |k, v|
      next unless k.is_a?(String) && k.to_s.start_with?(HTTP_PREFIX)

      k = k[5..-1].
        split(HTTP_HEADER_ORIGINAL_DELIMITER).
        each(&:capitalize!).
        join(HTTP_HEADER_NEW_DELIMITER)

      headers[k] = v
    end

    headers
  end
end
ip() click to toggle source
Calls superclass method
# File lib/logtail-rack/util/request.rb, line 44
def ip
  @ip ||= if @env[REMOTE_IP_KEY_NAME]
    @env[REMOTE_IP_KEY_NAME].to_s || super
  else
    super
  end
end
referer() click to toggle source
Calls superclass method
# File lib/logtail-rack/util/request.rb, line 52
def referer
  # Rails 3.X returns "/" for some reason
  @referer ||= super == "/" ? nil : super
end
request_id() click to toggle source
# File lib/logtail-rack/util/request.rb, line 57
def request_id
  @request_id ||= @env[REQUEST_ID_KEY_NAME1] ||
    @env[REQUEST_ID_KEY_NAME2]
end