From e63ee15254310a1d4c8b78953216fd90b69a2e9e Mon Sep 17 00:00:00 2001 From: Ken Mazaika Date: Fri, 30 Nov 2012 14:08:17 -0500 Subject: [PATCH] Add support for passing in ciphers information into the ConnectionAdapter, and have this work as expected with the Net:HTTP ConnectionAdapter. --- lib/httparty.rb | 15 ++++++++++++++- lib/httparty/connection_adapter.rb | 4 ++++ spec/httparty/connection_adapter_spec.rb | 9 +++++++++ spec/httparty_spec.rb | 8 ++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/httparty.rb b/lib/httparty.rb index 9885e58..570992e 100644 --- a/lib/httparty.rb +++ b/lib/httparty.rb @@ -299,7 +299,7 @@ module HTTParty default_options[:query_string_normalizer] = normalizer end - # Allows setting of SSL version to use. This only works in Ruby 1.9. + # 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 @@ -310,6 +310,19 @@ module HTTParty default_options[:ssl_version] = version end + # Allows setting of SSL ciphers to use. This only works in Ruby 1.9+. + # You can get a list of valid specific ciphers from OpenSSL::Cipher.ciphers. + # You also can specify a cipher suite here, listed here at openssl.org: + # http://www.openssl.org/docs/apps/ciphers.html#CIPHER_SUITE_NAMES + # + # class Foo + # include HTTParty + # ciphers "RC4-SHA" + # end + def ciphers(cipher_names) + default_options[:ciphers] = cipher_names + end + # Allows setting an OpenSSL certificate authority file # # class Foo diff --git a/lib/httparty/connection_adapter.rb b/lib/httparty/connection_adapter.rb index df3e0cc..c1f782b 100644 --- a/lib/httparty/connection_adapter.rb +++ b/lib/httparty/connection_adapter.rb @@ -76,6 +76,10 @@ module HTTParty http.set_debug_output(options[:debug_output]) end + if options[:ciphers] + http.ciphers = options[:ciphers] + end + return http end diff --git a/spec/httparty/connection_adapter_spec.rb b/spec/httparty/connection_adapter_spec.rb index f405e0f..9d30ca7 100644 --- a/spec/httparty/connection_adapter_spec.rb +++ b/spec/httparty/connection_adapter_spec.rb @@ -78,6 +78,7 @@ describe HTTParty::ConnectionAdapter do it { should use_ssl } end + context "when ssl version is set" do let(:options) { {:ssl_version => :TLSv1} } @@ -87,6 +88,14 @@ describe HTTParty::ConnectionAdapter do end if RUBY_VERSION > '1.9' end + context "specifying ciphers" do + let(:options) { {:ciphers => 'RC4-SHA' } } + + it "should set the ciphers on the connection" do + subject.ciphers.should == 'RC4-SHA' + end + end if RUBY_VERSION > '1.9' + context "when timeout is not set" do it "doesn't set the timeout" do http = mock("http", :null_object => true) diff --git a/spec/httparty_spec.rb b/spec/httparty_spec.rb index f62a322..402ec01 100644 --- a/spec/httparty_spec.rb +++ b/spec/httparty_spec.rb @@ -45,6 +45,14 @@ describe HTTParty do end end + describe 'ciphers' do + it 'should set the ciphers content' do + @klass.default_options[:ciphers].should be_nil + @klass.ciphers 'RC4-SHA' + @klass.default_options[:ciphers].should == 'RC4-SHA' + end + end + describe 'http_proxy' do it 'should set the address' do @klass.http_proxy 'proxy.foo.com', 80