lib/ably/rest/client.rb in ably-1.1.4 vs lib/ably/rest/client.rb in ably-1.1.5

- old
+ new

@@ -1,10 +1,13 @@ require 'faraday' require 'json' require 'logger' require 'uri' +require 'typhoeus' +require 'typhoeus/adapters/faraday' + require 'ably/rest/middleware/exceptions' module Ably module Rest # Client for the Ably REST API @@ -179,20 +182,22 @@ @add_request_ids = options.delete(:add_request_ids) @log_retries_as_info = options.delete(:log_retries_as_info) @idempotent_rest_publishing = options.delete(:idempotent_rest_publishing) || Ably.major_minor_version_numeric > 1.1 - if options[:fallback_hosts_use_default] && options[:fallback_jhosts] - raise ArgumentError, "fallback_hosts_use_default cannot be set to trye when fallback_jhosts is also provided" + if options[:fallback_hosts_use_default] && options[:fallback_hosts] + raise ArgumentError, "fallback_hosts_use_default cannot be set to try when fallback_hosts is also provided" end @fallback_hosts = case when options.delete(:fallback_hosts_use_default) Ably::FALLBACK_HOSTS when options_fallback_hosts = options.delete(:fallback_hosts) options_fallback_hosts - when environment || custom_host || options[:realtime_host] || custom_port || custom_tls_port + when custom_host || options[:realtime_host] || custom_port || custom_tls_port [] + when environment + CUSTOM_ENVIRONMENT_FALLBACKS_SUFFIXES.map { |host| "#{environment}#{host}" } else Ably::FALLBACK_HOSTS end options[:fallback_retry_timeout] ||= FALLBACK_RETRY_TIMEOUT @@ -200,10 +205,12 @@ # Take option keys prefixed with `http_`, remove the http_ and # check if the option exists in HTTP_DEFAULTS. If so, update http_defaults @http_defaults = HTTP_DEFAULTS.dup options.each do |key, val| if http_key = key[/^http_(.+)/, 1] + # Typhoeus converts decimal durations to milliseconds, so 0.0001 timeout is treated as 0 (no timeout) + val = 0.001 if val.kind_of?(Numeric) && (val > 0) && (val < 0.001) @http_defaults[http_key.to_sym] = val if val && @http_defaults.has_key?(http_key.to_sym) end end @http_defaults.freeze @@ -663,11 +670,11 @@ timeout: http_defaults.fetch(:request_timeout) } } end - # Return a Faraday middleware stack to initiate the Faraday::Connection with + # Return a Faraday middleware stack to initiate the Faraday::RackBuilder with # # @see http://mislav.uniqpath.com/2011/07/faraday-advanced-http/ def middleware @middleware ||= Faraday::RackBuilder.new do |builder| setup_outgoing_middleware builder @@ -675,11 +682,11 @@ # Raise exceptions if response code is invalid builder.use Ably::Rest::Middleware::Exceptions setup_incoming_middleware builder, logger, fail_if_unsupported_mime_type: true - # Set Faraday's HTTP adapter - builder.adapter :excon + # Set Faraday's HTTP adapter with support for HTTP/2 + builder.adapter :typhoeus, http_version: :httpv2_0 end end def can_fallback_to_alternate_ably_host? fallback_hosts && !fallback_hosts.empty?