lib/ezclient/request.rb in ezclient-1.2.0 vs lib/ezclient/request.rb in ezclient-1.3.0

- old
+ new

@@ -99,17 +99,27 @@ http_client end end def perform_request + with_retry do + # Use original client so that connection can be reused + # client.perform(http_request, http_options) + res = client.perform(http_request, http_options) + return res unless follow + + HTTP::Redirector.new(follow).perform(http_request, res) do |request| + client.perform(request, http_options) + end + end + end + + def with_retry(&block) retries = 0 begin - retry_on_connection_error do - # Use original client so that connection can be reused - client.perform(http_request, http_options) - end + retry_on_connection_error(&block) rescue *retried_exceptions => error if retries < max_retries.to_i retries += 1 on_retry.call(self, error, options[:metadata]) retry @@ -148,9 +158,14 @@ Array(options[:retry_exceptions]) end def max_retries options[:max_retries] || 1 + end + + def follow + return unless options[:follow] + options[:follow].is_a?(Hash) ? options[:follow] : {} end def prepare_headers(headers) headers = HTTP::Headers.coerce(headers) headers[:user_agent] ||= "ezclient/#{EzClient::VERSION}"