Permalink
Browse files

Merge branch 'ssl_version' of https://github.com/htanata/httparty int…

…o htanata-ssl_version

Conflicts:
	lib/httparty/request.rb
	spec/httparty/request_spec.rb
  • Loading branch information...
2 parents 22bd579 + 6b88a95 commit ad7681757fe1c1e88b2a498673c3cd7169173a1d @jnunemaker committed Sep 7, 2012
View
0 bin/httparty 100644 → 100755
No changes.
View
@@ -299,6 +299,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
@@ -105,6 +105,10 @@ def attach_ssl_certificates(http, options)
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
end
@@ -56,32 +56,35 @@
subject { adapter.connection }
it { should be_an_instance_of Net::HTTP }
+ context "using port 80" do
+ let(:uri) { URI 'http://foobar.com' }
+ it { should_not use_ssl }
+ end
+
context "when dealing with ssl" do
- Spec::Matchers.define :use_ssl do
- match do |connection|
- connection.use_ssl?
- end
- end
+ let(:uri) { URI 'https://foobar.com' }
context "using port 443 for ssl" do
let(:uri) { URI 'https://api.foo.com/v1:443' }
it { should use_ssl }
end
- context "using port 80" do
- let(:uri) { URI 'http://foobar.com' }
- it { should_not use_ssl }
- end
-
context "https scheme with default port" do
- let(:uri) { URI 'https://foobar.com' }
it { should use_ssl }
end
context "https scheme with non-standard port" do
let(:uri) { URI 'https://foobar.com:123456' }
it { should use_ssl }
end
+
+ context "when ssl version is set" do
+ let(:options) { {:ssl_version => :TLSv1} }
+
+ it "sets ssl version" do
+ subject.ssl_version.should == :TLSv1
+ end
+ end
end
context "when timeout is not set" do
@@ -199,6 +202,5 @@
end
end
end
-
end
end
@@ -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
View
@@ -22,3 +22,9 @@ def file_fixture(filename)
FakeWeb.allow_net_connect = true
end
end
+
+Spec::Matchers.define :use_ssl do
+ match do |connection|
+ connection.use_ssl?
+ end
+end

0 comments on commit ad76817

Please sign in to comment.