Skip to content

Commit

Permalink
Merge branch 'ssl_version' of https://github.com/htanata/httparty int…
Browse files Browse the repository at this point in the history
…o htanata-ssl_version

Conflicts:
	lib/httparty/request.rb
	spec/httparty/request_spec.rb
  • Loading branch information
jnunemaker committed Sep 7, 2012
2 parents 22bd579 + 6b88a95 commit ad76817
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 deletions.
Empty file modified bin/httparty 100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions lib/httparty.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/httparty/connection_adapter.rb
Expand Up @@ -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
Expand Down
26 changes: 14 additions & 12 deletions spec/httparty/connection_adapter_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -199,6 +202,5 @@
end
end
end

end
end
7 changes: 7 additions & 0 deletions spec/httparty_spec.rb
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
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -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.