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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ldclient-rb/util.rb', line 14 def self.add_payload_filter_key(uri, config) return uri if config.payload_filter_key.nil? unless config.payload_filter_key.is_a?(String) && !config.payload_filter_key.empty? config.logger.warn { "[LDClient] Filter key must be a non-empty string. No filtering will be applied." } return uri end 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
68 69 70 71 72 |
# File 'lib/ldclient-rb/util.rb', line 68 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
60 61 62 63 64 65 66 |
# File 'lib/ldclient-rb/util.rb', line 60 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
55 56 57 58 |
# File 'lib/ldclient-rb/util.rb', line 55 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ldclient-rb/util.rb', line 33 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 |