mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Merge branch 'ssl_version' of https://github.com/htanata/httparty into htanata-ssl_version
Conflicts: lib/httparty/request.rb spec/httparty/request_spec.rb
This commit is contained in:
commit
ad7681757f
6 changed files with 42 additions and 12 deletions
0
bin/httparty
Normal file → Executable file
0
bin/httparty
Normal file → Executable file
|
@ -299,6 +299,17 @@ module HTTParty
|
||||||
default_options[:query_string_normalizer] = normalizer
|
default_options[:query_string_normalizer] = normalizer
|
||||||
end
|
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
|
# Allows setting an OpenSSL certificate authority file
|
||||||
#
|
#
|
||||||
# class Foo
|
# class Foo
|
||||||
|
|
|
@ -105,6 +105,10 @@ module HTTParty
|
||||||
http.ca_path = options[:ssl_ca_path]
|
http.ca_path = options[:ssl_ca_path]
|
||||||
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if options[:ssl_version] && http.respond_to?(:ssl_version=)
|
||||||
|
http.ssl_version = options[:ssl_version]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,25 +56,20 @@ describe HTTParty::ConnectionAdapter do
|
||||||
subject { adapter.connection }
|
subject { adapter.connection }
|
||||||
it { should be_an_instance_of Net::HTTP }
|
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
|
context "when dealing with ssl" do
|
||||||
Spec::Matchers.define :use_ssl do
|
let(:uri) { URI 'https://foobar.com' }
|
||||||
match do |connection|
|
|
||||||
connection.use_ssl?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "using port 443 for ssl" do
|
context "using port 443 for ssl" do
|
||||||
let(:uri) { URI 'https://api.foo.com/v1:443' }
|
let(:uri) { URI 'https://api.foo.com/v1:443' }
|
||||||
it { should use_ssl }
|
it { should use_ssl }
|
||||||
end
|
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
|
context "https scheme with default port" do
|
||||||
let(:uri) { URI 'https://foobar.com' }
|
|
||||||
it { should use_ssl }
|
it { should use_ssl }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,6 +77,14 @@ describe HTTParty::ConnectionAdapter do
|
||||||
let(:uri) { URI 'https://foobar.com:123456' }
|
let(:uri) { URI 'https://foobar.com:123456' }
|
||||||
it { should use_ssl }
|
it { should use_ssl }
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "when timeout is not set" do
|
context "when timeout is not set" do
|
||||||
|
@ -199,6 +202,5 @@ describe HTTParty::ConnectionAdapter do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,6 +38,13 @@ describe HTTParty do
|
||||||
end
|
end
|
||||||
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
|
describe 'http_proxy' do
|
||||||
it 'should set the address' do
|
it 'should set the address' do
|
||||||
@klass.http_proxy 'proxy.foo.com', 80
|
@klass.http_proxy 'proxy.foo.com', 80
|
||||||
|
|
|
@ -22,3 +22,9 @@ Spec::Runner.configure do |config|
|
||||||
FakeWeb.allow_net_connect = true
|
FakeWeb.allow_net_connect = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Spec::Matchers.define :use_ssl do
|
||||||
|
match do |connection|
|
||||||
|
connection.use_ssl?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue