From 43519c40003b8ed14c9e449a0def0ff29ac27f15 Mon Sep 17 00:00:00 2001 From: Dalibor Nasevic Date: Mon, 21 Jan 2019 15:17:54 +0100 Subject: [PATCH] Cache default certs store (#625) --- lib/httparty/connection_adapter.rb | 9 +++++++-- spec/spec_helper.rb | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/httparty/connection_adapter.rb b/lib/httparty/connection_adapter.rb index 5b5193a..654168e 100644 --- a/lib/httparty/connection_adapter.rb +++ b/lib/httparty/connection_adapter.rb @@ -77,6 +77,12 @@ module HTTParty new(uri, options).connection end + def self.default_cert_store + @default_cert_store ||= OpenSSL::X509::Store.new.tap do |cert_store| + cert_store.set_default_paths + end + end + attr_reader :uri, :options def initialize(uri, options = {}) @@ -176,8 +182,7 @@ module HTTParty http.cert_store = options[:cert_store] else # Use the default cert store by default, i.e. system ca certs - http.cert_store = OpenSSL::X509::Store.new - http.cert_store.set_default_paths + http.cert_store = self.class.default_cert_store end else http.verify_mode = OpenSSL::SSL::VERIFY_NONE diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d8622a4..c638b91 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -37,6 +37,11 @@ RSpec.configure do |config| config.order = :random + config.before(:each) do + # Reset default_cert_store cache + HTTParty::ConnectionAdapter.instance_variable_set(:@default_cert_store, nil) + end + Kernel.srand config.seed end