Sha256: 8b9ca6bbe52a6eb2ec35fb4cc2d0309df70ea0e707221c19a418cc97abadae5e

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
# frozen_string_literal: true

require_relative 'abstract'

module NewRelic
  module Agent
    module HTTPClients
      class HTTPResponse < AbstractResponse
        def [](key)
          _, value = @wrapped_response.headers.find{ |k, _| key.downcase == k.downcase }
          value unless value.nil?
        end

        def to_hash
          @wrapped_response.headers
        end
      end

      class HTTPRequest < AbstractRequest
        HTTP_RB = 'http.rb'
        HOST    = 'host'
        COLON   = ':'

        def initialize wrapped_request
          @wrapped_request = wrapped_request
        end

        def uri
          @uri ||= URIUtil.parse_and_normalize_url(@wrapped_request.uri)
        end

        def type
          HTTP_RB
        end

        def host_from_header
          if hostname = self[HOST]
            hostname.split(COLON).first
          end
        end

        def host
          host_from_header || @wrapped_request.host
        end

        def method
          @wrapped_request.verb.upcase
        end

        def [](key)
          @wrapped_request.headers[key]
        end

        def []=(key, value)
          @wrapped_request.headers[key] = value
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
newrelic_rpm-6.11.0.365 lib/new_relic/agent/http_clients/http_rb_wrappers.rb
newrelic_rpm-6.10.0.364 lib/new_relic/agent/http_clients/http_rb_wrappers.rb