lib/ably/rest/client.rb in ably-1.1.3 vs lib/ably/rest/client.rb in ably-1.1.4.rc
- 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
@@ -200,10 +203,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
@@ -664,11 +669,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
@@ -676,11 +681,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?