class ReportPortal::HttpClient
@api private
Public Class Methods
new()
click to toggle source
# File lib/report_portal/http_client.rb, line 6 def initialize create_client end
Public Instance Methods
send_request(verb, path, options = {})
click to toggle source
# File lib/report_portal/http_client.rb, line 10 def send_request(verb, path, options = {}) path.prepend("/api/v1/#{Settings.instance.project}/") path.prepend(origin) unless use_persistent? 3.times do begin response = @http.request(verb, path, options) rescue StandardError => e puts "Request #{request_info(verb, path)} produced an exception:" puts e recreate_client else return response.parse(:json) if response.status.success? message = "Request #{request_info(verb, path)} returned code #{response.code}." message << " Response:\n#{response}" unless response.to_s.empty? puts message end end end
Private Instance Methods
add_insecure_ssl_options()
click to toggle source
# File lib/report_portal/http_client.rb, line 38 def add_insecure_ssl_options ssl_context = OpenSSL::SSL::SSLContext.new ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE @http.default_options = { ssl_context: ssl_context } end
create_client()
click to toggle source
# File lib/report_portal/http_client.rb, line 32 def create_client @http = HTTP.auth("Bearer #{Settings.instance.uuid}") @http = @http.persistent(origin) if use_persistent? add_insecure_ssl_options if Settings.instance.disable_ssl_verification end
origin()
click to toggle source
# File lib/report_portal/http_client.rb, line 56 def origin Addressable::URI.parse(Settings.instance.endpoint).origin end
recreate_client()
click to toggle source
Response should be consumed before sending next request via the same persistent connection. If an exception occurred, there may be no response so a connection has to be recreated.
# File lib/report_portal/http_client.rb, line 46 def recreate_client @http.close create_client end
request_info(verb, path)
click to toggle source
# File lib/report_portal/http_client.rb, line 51 def request_info(verb, path) uri = URI.join(origin, path) "#{verb.upcase} `#{uri}`" end
use_persistent?()
click to toggle source
# File lib/report_portal/http_client.rb, line 60 def use_persistent? ReportPortal::Settings.instance.formatter_modes.include?('use_persistent_connection') end