Sha256: 4a34390e92d7ae0d875581c7f62b8cd3c592d8f33578555862f1e1fd21186a95

Contents?: true

Size: 1.73 KB

Versions: 24

Compression:

Stored size: 1.73 KB

Contents

# -*- ruby -*-
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

# This module includes utilities for manipulating URIs, particularly from the
# context of Net::HTTP requests. We don't always have direct access to the full
# URI from our instrumentation points in Net::HTTP, and we want to filter out
# some URI parts before saving URIs from instrumented calls - logic for that
# lives here.

module NewRelic
  module Agent
    module HTTPClients
      module URIUtil
        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

        # 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.
        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

        QUESTION_MARK = '?'

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

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
newrelic_rpm-9.16.0 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.15.0 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.14.0 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.13.0 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.12.0 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.11.0 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.10.2 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.10.1 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.10.0 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.9.0 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.8.0 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.7.1 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.7.0 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.6.0 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.5.0 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.4.2 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.4.1 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.4.0 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.3.1 lib/new_relic/agent/http_clients/uri_util.rb
newrelic_rpm-9.3.0 lib/new_relic/agent/http_clients/uri_util.rb