Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add ssl_version option to choose SSL version to use #159

Merged
merged 2 commits into from

4 participants

@htanata

This allows us to do these things:

# Per class option:
class Foo
  include HTTParty

  ssl_version :SSLv3
end

# Override default option:
Foo.get '/list', :ssl_version => :SSLv23

# Per request option:
HTTParty.get 'https://foobar.com/list', :ssl_version => :TLSv1
@travisbot

This pull request fails (merged c2cf65f into 9c08f47).

@travisbot

This pull request fails (merged 628f29f1 into 9c08f47).

@travisbot

This pull request passes (merged 6b88a95 into 9c08f47).

@maxstoller

Bump :grin:

@jnunemaker jnunemaker merged commit 6b88a95 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
0  bin/httparty 100644 → 100755
File mode changed
View
11 lib/httparty.rb
@@ -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
View
4 lib/httparty/request.rb
@@ -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
View
8 spec/httparty/request_spec.rb
@@ -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)
View
7 spec/httparty_spec.rb
@@ -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
Something went wrong with that request. Please try again.