Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/httparty/connection_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module HTTParty
# * :+pem+: contains pem client certificate data. see method 'attach_ssl_certificates'
# * :+p12+: contains PKCS12 client client certificate data. see method 'attach_ssl_certificates'
# * :+verify+: verify the server’s certificate against the ca certificate.
# * :+verify_callback+: a Proc that will be called to verify the server’s certificate. see method 'attach_ssl_certificates'
# * :+verify_peer+: set to false to turn off server verification but still send client certificate
# * :+ssl_ca_file+: see HTTParty::ClassMethods.ssl_ca_file.
# * :+ssl_ca_path+: see HTTParty::ClassMethods.ssl_ca_path.
Expand Down Expand Up @@ -227,6 +228,10 @@ def attach_ssl_certificates(http, options)
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
end

if options[:verify_callback]
http.verify_callback = options[:verify_callback]
end

# This is only Ruby 1.9+
if options[:ssl_version] && http.respond_to?(:ssl_version=)
http.ssl_version = options[:ssl_version]
Expand Down
27 changes: 27 additions & 0 deletions spec/httparty/connection_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,33 @@
it { expect(subject.port).to be 443 }
end
end

context "when providing verify_callback" do
let(:verify_callback) { double("verify_callback") }
let(:options) { {verify_callback: verify_callback} }

context "when scheme is https" do
let(:uri) { URI 'https://google.com' }

it "uses the provided verify_callback" do
expect(subject.verify_callback).to be verify_callback
end
end

context "when scheme is not https" do
let(:uri) { URI 'http://google.com' }
let(:http) { Net::HTTP.new(uri) }

before do
allow(Net::HTTP).to receive_messages(new: http)
expect(http).not_to receive(:verify_callback=)
end

it "has no verify_callback " do
expect(subject.verify_callback).to be_nil
end
end
end
end
end
end