Module: Datadog::Core::Utils::Network

Defined in:
lib/datadog/core/utils/network.rb

Overview

Common Network utility functions.

Constant Summary collapse

DEFAULT_IP_HEADERS_NAMES =
%w[
  x-forwarded-for
  x-real-ip
  true-client-ip
  x-client-ip
  x-forwarded
  forwarded-for
  x-cluster-client-ip
  fastly-client-ip
  cf-connecting-ip
  cf-connecting-ipv6
].freeze

Class Method Summary collapse

Class Method Details

.stripped_ip(ip) ⇒ String?

Parameters:

  • IP (String)

    value.

Returns:

  • (String)

    IP value without the port and the zone indentifier.

  • (nil)

    when no valid IP value found.



41
42
43
44
# File 'lib/datadog/core/utils/network.rb', line 41

def stripped_ip(ip)
  ip = ip_to_ipaddr(ip)
  ip ? ip.to_s : nil
end

.stripped_ip_from_request_headers(headers, ip_headers_to_check: DEFAULT_IP_HEADERS_NAMES) ⇒ String?

Returns a client IP associated with the request if it was

retrieved successfully.

Parameters:

Returns:

  • (String)

    IP value without the port and the zone indentifier.

  • (nil)

    when no valid IP value found.



32
33
34
35
36
# File 'lib/datadog/core/utils/network.rb', line 32

def stripped_ip_from_request_headers(headers, ip_headers_to_check: DEFAULT_IP_HEADERS_NAMES)
  ip = ip_header(headers, ip_headers_to_check)

  ip ? ip.to_s : nil
end