Module: LaunchDarkly::Util
- Defined in:
- lib/ldclient-rb/util.rb
Class Method Summary collapse
-
.add_payload_filter_key(uri, config) ⇒ String
Append the payload filter key query parameter to the provided URI.
- .http_error_message(status, context, recoverable_message) ⇒ Object
- .http_error_recoverable?(status) ⇒ Boolean
- .log_exception(logger, message, exc) ⇒ Object
- .new_http_client(uri_s, config) ⇒ Object
Class Method Details
.add_payload_filter_key(uri, config) ⇒ String
Append the payload filter key query parameter to the provided URI.
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ldclient-rb/util.rb', line 77 def self.add_payload_filter_key(uri, config) return uri if config.payload_filter_key.nil? begin parsed = URI.parse(uri) new_query_params = URI.decode_www_form(String(parsed.query)) << ["filter", config.payload_filter_key] parsed.query = URI.encode_www_form(new_query_params) parsed.to_s rescue URI::InvalidURIError config.logger.warn { "[LDClient] URI could not be parsed. No filtering will be applied." } uri end end |
.http_error_message(status, context, recoverable_message) ⇒ Object
126 127 128 129 130 |
# File 'lib/ldclient-rb/util.rb', line 126 def self.(status, context, ) desc = (status == 401 || status == 403) ? " (invalid SDK key)" : "" = Util.http_error_recoverable?(status) ? : "giving up permanently" "HTTP error #{status}#{desc} for #{context} - #{}" end |
.http_error_recoverable?(status) ⇒ Boolean
118 119 120 121 122 123 124 |
# File 'lib/ldclient-rb/util.rb', line 118 def self.http_error_recoverable?(status) if status >= 400 && status < 500 status == 400 || status == 408 || status == 429 else true end end |
.log_exception(logger, message, exc) ⇒ Object
113 114 115 116 |
# File 'lib/ldclient-rb/util.rb', line 113 def self.log_exception(logger, , exc) logger.error { "[LDClient] #{}: #{exc.inspect}" } logger.debug { "[LDClient] Exception trace: #{exc.backtrace}" } end |
.new_http_client(uri_s, config) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ldclient-rb/util.rb', line 91 def self.new_http_client(uri_s, config) = {} if config.socket_factory ["socket_class"] = config.socket_factory end proxy = URI.parse(uri_s).find_proxy unless proxy.nil? ["proxy"] = { proxy_address: proxy.host, proxy_port: proxy.port, proxy_username: proxy.user, proxy_password: proxy.password, } end HTTP::Client.new() .timeout({ read: config.read_timeout, connect: config.connect_timeout, }) .persistent(uri_s) end |