Module: NewRelic::Agent::HTTPClients::URIUtil

Defined in:
lib/new_relic/agent/http_clients/uri_util.rb

Constant Summary collapse

QUESTION_MARK =
'?'

Class Method Summary collapse

Class Method Details

.obfuscated_uri(url) ⇒ Object

[View source]

16
17
18
19
20
21
22
23
# File 'lib/new_relic/agent/http_clients/uri_util.rb', line 16

def self.obfuscated_uri(url)
  parse_and_normalize_url(url).tap do |obfuscated|
    obfuscated.user = nil
    obfuscated.password = nil
    obfuscated.query = nil
    obfuscated.fragment = nil
  end
end

.parse_and_normalize_url(url) ⇒ Object

There are valid URI strings that some HTTP client libraries will accept that the stdlib URI module doesn’t handle. If we find that Addressable is around, use that to normalize out our URL’s.

[View source]

28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/new_relic/agent/http_clients/uri_util.rb', line 28

def self.parse_and_normalize_url(url)
  uri = url.dup
  unless ::URI === uri
    if defined?(::Addressable::URI)
      address = ::Addressable::URI.parse(url)
      address.normalize!
      uri = ::URI.parse(address.to_s)
    else
      uri = ::URI.parse(url)
    end
  end
  uri.host&.downcase!
  uri
end

.strip_query_string(fragment) ⇒ Object

[View source]

45
46
47
48
49
50
51
# File 'lib/new_relic/agent/http_clients/uri_util.rb', line 45

def self.strip_query_string(fragment)
  if fragment.include?(QUESTION_MARK)
    fragment.split(QUESTION_MARK).first
  else
    fragment
  end
end