lib/elasticsearch/transport/transport/base.rb in elasticsearch-transport-7.14.1.pre vs lib/elasticsearch/transport/transport/base.rb in elasticsearch-transport-7.14.1

- old
+ new

@@ -270,11 +270,10 @@ elsif options.key?(:retry_on_failure) options[:retry_on_failure] === true ? DEFAULT_MAX_RETRIES : options[:retry_on_failure] end params = params.clone - ignore = Array(params.delete(:ignore)).compact.map { |s| s.to_i } begin tries += 1 connection = get_connection or raise Error.new('Cannot get new connection from pool.') @@ -282,13 +281,11 @@ if connection.connection.respond_to?(:params) && connection.connection.params.respond_to?(:to_hash) params = connection.connection.params.merge(params.to_hash) end url = connection.full_url(path, params) - response = block.call(connection, url) - connection.healthy! if connection.failures > 0 # Raise an exception so we can catch it for `retry_on_status` __raise_transport_error(response) if response.status.to_i >= 300 && @retry_on_status.include?(response.status.to_i) @@ -334,32 +331,26 @@ end #/begin duration = Time.now - start if response.status.to_i >= 300 - __log_response method, path, params, body, url, response, nil, 'N/A', duration - __trace method, path, params, connection.connection.headers, body, url, response, nil, 'N/A', duration if tracer - + __log_response(method, path, params, body, url, response, nil, 'N/A', duration) + __trace(method, path, params, connection_headers(connection), body, url, response, nil, 'N/A', duration) if tracer # Log the failure only when `ignore` doesn't match the response status - unless ignore.include?(response.status.to_i) - log_fatal "[#{response.status}] #{response.body}" - end - + log_fatal "[#{response.status}] #{response.body}" unless ignore.include?(response.status.to_i) __raise_transport_error response unless ignore.include?(response.status.to_i) end json = serializer.load(response.body) if response.body && !response.body.empty? && response.headers && response.headers["content-type"] =~ /json/ took = (json['took'] ? sprintf('%.3fs', json['took']/1000.0) : 'n/a') rescue 'n/a' unless ignore.include?(response.status.to_i) __log_response method, path, params, body, url, response, json, took, duration end - __trace method, path, params, connection.connection.headers, body, url, response, nil, 'N/A', duration if tracer - + __trace(method, path, params, connection_headers(connection), body, url, response, nil, 'N/A', duration) if tracer warnings(response.headers['warning']) if response.headers&.[]('warning') - Response.new response.status, json || response.body, response.headers ensure @last_request_at = Time.now end @@ -432,9 +423,17 @@ end end def warnings(warning) warn("warning: #{warning}") + end + + def connection_headers(connection) + if defined?(Elasticsearch::Transport::Transport::HTTP::Manticore) && self.class == Elasticsearch::Transport::Transport::HTTP::Manticore + @request_options[:headers] + else + connection.connection.headers + end end end end end end