Sha256: c4058ff53dee46c204193cbfe4345f8946cc3d491c9178758cc653d5ebe9dfdb

Contents?: true

Size: 1.28 KB

Versions: 8

Compression:

Stored size: 1.28 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.

module NewRelic
  module Agent
    module HTTPClients
      class HTTPResponse
        attr_reader :response

        def initialize(response)
          @response = response
        end

        def [](key)
          _, value = response.headers.find { |k,_| key.downcase == k.downcase }
          value unless value.nil?
        end

        def to_hash
          response.headers
        end
      end

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

        attr_reader :request, :uri

        def initialize(request)
          @request = request
          @uri = 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 || request.host
        end

        def method
          request.verb.upcase
        end

        def [](key)
          request.headers[key]
        end

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
newrelic_rpm-4.5.0.337 lib/new_relic/agent/http_clients/http_rb_wrappers.rb
newrelic_rpm-4.4.0.336 lib/new_relic/agent/http_clients/http_rb_wrappers.rb
newrelic_rpm-4.3.0.335 lib/new_relic/agent/http_clients/http_rb_wrappers.rb
newrelic_rpm-4.2.0.334 lib/new_relic/agent/http_clients/http_rb_wrappers.rb
newrelic_rpm-4.1.0.333 lib/new_relic/agent/http_clients/http_rb_wrappers.rb
newrelic_rpm-4.0.0.332 lib/new_relic/agent/http_clients/http_rb_wrappers.rb
newrelic_rpm-3.18.1.330 lib/new_relic/agent/http_clients/http_rb_wrappers.rb
newrelic_rpm-3.18.0.329 lib/new_relic/agent/http_clients/http_rb_wrappers.rb