Sha256: 2d31e0bf97a72552b49d47219d62592349664baf333c85d313b4e801d66b55c8

Contents?: true

Size: 1.69 KB

Versions: 15

Compression:

Stored size: 1.69 KB

Contents

# 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

require_relative 'abstract'
require 'resolv'

module NewRelic
  module Agent
    module HTTPClients
      class AsyncHTTPResponse < AbstractResponse
        def get_status_code
          get_status_code_using(:status)
        end

        def [](key)
          to_hash[key.downcase]&.first
        end

        def to_hash
          @wrapped_response.headers.to_h
        end
      end

      class AsyncHTTPRequest < AbstractRequest
        def initialize(connection, method, url, headers)
          @connection = connection
          @method = method
          @url = ::NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(url)
          @headers = headers
        end

        ASYNC_HTTP = 'Async::HTTP'

        def type
          ASYNC_HTTP
        end

        def host_from_header
          if hostname = (self[LHOST] || self[UHOST])
            hostname.split(COLON).first
          end
        end

        def host
          host_from_header || uri.host.to_s
        end

        def [](key)
          return headers[key] unless headers.is_a?(Array)

          headers.each do |header|
            return header[1] if header[0].casecmp?(key)
          end
          nil
        end

        def []=(key, value)
          if headers.is_a?(Array)
            headers << [key, value]
          else
            headers[key] = value
          end
        end

        def uri
          @url
        end

        def headers
          @headers
        end

        def method
          @method
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
newrelic_rpm-9.17.0 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.16.1 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.16.0 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.15.0 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.14.0 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.13.0 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.12.0 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.11.0 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.10.2 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.10.1 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.10.0 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.9.0 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.8.0 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.7.1 lib/new_relic/agent/http_clients/async_http_wrappers.rb
newrelic_rpm-9.7.0 lib/new_relic/agent/http_clients/async_http_wrappers.rb