Skip to content

Commit

Permalink
Add support for passing in ciphers information into the ConnectionAda…
Browse files Browse the repository at this point in the history
…pter, and have this work as expected with the Net:HTTP ConnectionAdapter.
  • Loading branch information
metropolis-testman committed Jan 2, 2013
1 parent d392c2d commit e63ee15
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/httparty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ 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.
# 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
Expand All @@ -310,6 +310,19 @@ def ssl_version(version)
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
Expand Down
4 changes: 4 additions & 0 deletions lib/httparty/connection_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def connection
http.set_debug_output(options[:debug_output])
end

if options[:ciphers]
http.ciphers = options[:ciphers]
end

return http
end

Expand Down
9 changes: 9 additions & 0 deletions spec/httparty/connection_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
it { should use_ssl }
end


context "when ssl version is set" do
let(:options) { {:ssl_version => :TLSv1} }

Expand All @@ -87,6 +88,14 @@
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)
Expand Down
8 changes: 8 additions & 0 deletions spec/httparty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
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
Expand Down

0 comments on commit e63ee15

Please sign in to comment.