Skip to content

Commit

Permalink
Merge pull request #14 from zzak/614c023
Browse files Browse the repository at this point in the history
check if fakeweb or webmock are loaded and disable SSL session reuse automatically #13
  • Loading branch information
drbrain committed Feb 2, 2012
2 parents 4079a27 + 614c023 commit 0842897
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/net/http/persistent.rb
Expand Up @@ -452,7 +452,12 @@ def finish connection
end

def http_class # :nodoc:
@reuse_ssl_sessions ? Net::HTTP::Persistent::SSLReuse : Net::HTTP
if [:FakeWeb, :WebMock].any? { |klass| Object.const_defined?(klass) } or
not @reuse_ssl_sessions then
Net::HTTP
else
Net::HTTP::Persistent::SSLReuse
end
end

##
Expand Down
20 changes: 20 additions & 0 deletions test/test_net_http_persistent.rb
Expand Up @@ -273,6 +273,26 @@ def test_connection_for_no_ssl_reuse
assert_instance_of Net::HTTP, c
end

def test_connection_for_http_class_with_fakeweb
Object.send :const_set, :FakeWeb, nil
c = @http.connection_for @uri
assert_instance_of Net::HTTP, c
ensure
if Object.const_defined?(:FakeWeb) then
Object.send :remove_const, :FakeWeb
end
end

def test_connection_for_http_class_with_webmock
Object.send :const_set, :WebMock, nil
c = @http.connection_for @uri
assert_instance_of Net::HTTP, c
ensure
if Object.const_defined?(:WebMock) then
Object.send :remove_const, :WebMock
end
end

def test_connection_for_proxy
uri = URI.parse 'http://proxy.example'
uri.user = 'johndoe'
Expand Down

0 comments on commit 0842897

Please sign in to comment.