Sha256: e73af788d65fce65a39e211d8cd4f999c5f89e9c6d144a7196b7286eeffa7bcf

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

require "uri"
require "http"

module LaunchDarkly
  # @private
  module Util
    def self.new_http_client(uri_s, config)
      http_client_options = {}
      if config.socket_factory
        http_client_options["socket_class"] = config.socket_factory
      end
      proxy = URI.parse(uri_s).find_proxy
      unless proxy.nil?
        http_client_options["proxy"] = {
          proxy_address: proxy.host,
          proxy_port: proxy.port,
          proxy_username: proxy.user,
          proxy_password: proxy.password,
        }
      end
      HTTP::Client.new(http_client_options)
        .timeout({
          read: config.read_timeout,
          connect: config.connect_timeout,
        })
        .persistent(uri_s)
    end

    def self.log_exception(logger, message, exc)
      logger.error { "[LDClient] #{message}: #{exc.inspect}" }
      logger.debug { "[LDClient] Exception trace: #{exc.backtrace}" }
    end

    def self.http_error_recoverable?(status)
      if status >= 400 && status < 500
        status == 400 || status == 408 || status == 429
      else
        true
      end
    end

    def self.http_error_message(status, context, recoverable_message)
      desc = (status == 401 || status == 403) ? " (invalid SDK key)" : ""
      message = Util.http_error_recoverable?(status) ? recoverable_message : "giving up permanently"
      "HTTP error #{status}#{desc} for #{context} - #{message}"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
launchdarkly-server-sdk-7.0.4 lib/ldclient-rb/util.rb
launchdarkly-server-sdk-7.0.3 lib/ldclient-rb/util.rb
launchdarkly-server-sdk-7.0.2 lib/ldclient-rb/util.rb
launchdarkly-server-sdk-7.0.1 lib/ldclient-rb/util.rb
launchdarkly-server-sdk-7.0.0 lib/ldclient-rb/util.rb