Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ssl_version option to choose SSL version to use #159

Merged
merged 2 commits into from
Sep 7, 2012
Merged
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
Empty file modified bin/httparty
100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions lib/httparty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@ def query_string_normalizer(normalizer)
default_options[:query_string_normalizer] = normalizer
end

# Allows setting of SSL version to use. This only works in Ruby 1.9.
# You can get a list of valid versions from OpenSSL::SSL::SSLContext::METHODS.
#
# class Foo
# include HTTParty
# ssl_version :SSLv3
# end
def ssl_version(version)
default_options[:ssl_version] = version
end

# Allows setting an OpenSSL certificate authority file
#
# class Foo
Expand Down
4 changes: 4 additions & 0 deletions lib/httparty/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def attach_ssl_certificates(http)
http.ca_path = options[:ssl_ca_path]
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
end

if options[:ssl_version] && http.respond_to?(:ssl_version=)
http.ssl_version = options[:ssl_version]
end
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/httparty/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@
request.send(:http).use_ssl?.should == true
end

it 'uses specified ssl_version' do
request = HTTParty::Request.new(Net::HTTP::Get, 'https://foobar.com', :ssl_version => :TLSv1)
http = request.send(:http)
if http.respond_to?(:ssl_version)
http.ssl_version.should == :TLSv1
end
end

context "PEM certificates" do
before do
OpenSSL::X509::Certificate.stub(:new)
Expand Down
7 changes: 7 additions & 0 deletions spec/httparty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
end
end

describe 'ssl_version' do
it 'should set the ssl_version content' do
@klass.ssl_version :SSLv3
@klass.default_options[:ssl_version].should == :SSLv3
end
end

describe 'http_proxy' do
it 'should set the address' do
@klass.http_proxy 'proxy.foo.com', 80
Expand Down