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

- old
+ new

@@ -1,13 +1,10 @@ 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 @@ -203,12 +200,10 @@ # 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 @@ -346,18 +341,18 @@ # @param body [Hash, nil] Optional body for the POST or PUT request, must be nil or a JSON-like object # @param headers [Hash, nil] Optional additional headers # # @return [Ably::Models::HttpPaginatedResponse<>] def request(method, path, params = {}, body = nil, headers = {}, options = {}) - raise "Method #{method.to_s.upcase} not supported" unless [:get, :put, :post].include?(method.to_sym) + raise "Method #{method.to_s.upcase} not supported" unless %i(get put patch post delete).include?(method.to_sym) response = case method.to_sym - when :get + when :get, :delete reauthorize_on_authorization_failure do send_request(method, path, params, headers: headers) end - when :post + when :post, :patch, :put path_with_params = Addressable::URI.new path_with_params.query_values = params || {} query = path_with_params.query reauthorize_on_authorization_failure do send_request(method, "#{path}#{"?#{query}" unless query.nil? || query.empty?}", body, headers: headers) @@ -574,14 +569,13 @@ if options[:qs_params] request.params.merge!(options[:qs_params]) end unless options[:send_auth_header] == false request.headers[:authorization] = auth.auth_header - if options[:headers] - options[:headers].map do |key, val| - request.headers[key] = val - end + + options[:headers].to_h.merge(auth.extra_auth_headers).map do |key, val| + request.headers[key] = val end end end.tap do if retry_count > 0 retry_log_severity = log_retries_as_info ? :info : :warn @@ -669,11 +663,11 @@ timeout: http_defaults.fetch(:request_timeout) } } end - # Return a Faraday middleware stack to initiate the Faraday::RackBuilder with + # Return a Faraday middleware stack to initiate the Faraday::Connection with # # @see http://mislav.uniqpath.com/2011/07/faraday-advanced-http/ def middleware @middleware ||= Faraday::RackBuilder.new do |builder| setup_outgoing_middleware builder @@ -681,11 +675,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 with support for HTTP/2 - builder.adapter :typhoeus, http_version: :httpv2_0 + # Set Faraday's HTTP adapter + builder.adapter :excon end end def can_fallback_to_alternate_ably_host? fallback_hosts && !fallback_hosts.empty?