Skip to content

Commit

Permalink
Cache default certs store (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
dalibor authored and TheSmartnik committed Jan 21, 2019
1 parent d84a05b commit 43519c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/httparty/connection_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def self.call(uri, options)
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 = {})
Expand Down Expand Up @@ -176,8 +182,7 @@ def attach_ssl_certificates(http, options)
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
Expand Down
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def file_fixture(filename)

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

Expand Down

0 comments on commit 43519c4

Please sign in to comment.