Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add keep-alive support #171

Open
wants to merge 2 commits into from
@byroot

I simply use net/http/persistent for easy keep-alive implementation

A little benchmark:

require './rest-client'
require 'benchmark'

puts Benchmark.measure{ 10.times{ RestClient.get('http://www.google.com/').length } }
RestClient.persistent = true
puts Benchmark.measure{ 10.times{ RestClient.get('http://www.google.com/').length } }

I get those numbers

  0.080000   0.010000   0.090000 (  1.365598)
  0.030000   0.000000   0.030000 (  0.354387)

For now the integration is a bit "Quick & Dirty". It's just to show the eventual benefits.
But if you like the idea I can clean it up and add test coverage.

Regards,

@L2G
Owner

I dig this. I haven't looked at it yet, but I can't believe no one's done it yet. :smile_cat:

@byroot

Probably because of #44. Somebody said it's not thread-safe which is false.

@L2G
Owner

Or, since that was a concern raised a couple of years ago, it may have been true for Ruby 1.8.x but no longer true for >= 1.9.1? (I'm not concerned with keeping compatible with 1.8.x as I believe it's being "sunsetted" soon.)

@byroot

Anyway you don't have to worry because it's thread-safe from day one: https://github.com/drbrain/net-http-persistent/tree/v1.0

Their statement is right, reusing the same connection prevent thread safety, unless you keep one connection per thread, and this it what net/http/persistent do.

@L2G
Owner

Ahh, okay.

@byroot

IHMO the question is more: should it be implemented as an option, or should we always use persistent connections if available.

I'm more for the second one, because it lead to a simpler code and IHMO persistent connections are preferable in most real world cases.

But I'm no maintainer.

@L2G
Owner

I think using persistent connections when available is a reasonable default, but then there should be an option to turn it off in case of unforeseen situations where it causes problems or just doesn't work as it should.

@byroot

Ok then, I'll try to update this PR soon.

@byroot

I've refactored the code, and updated the test suite.
Now all connections are handled by Net::HTTP::Persistent, but when asked to do so connections are automatically closed.
I also use two distinct pools of connection so you can use both at the same time.

Persistent connections are now the default, but can be turned off globaly with

RestClient.persistent = false

Or on a request basis by passing :persistent => false

If you are not confident with making persistent connections the default you can
easily revert it by removing the @persistent = true line in restclient.rb.
The test suite will pass whatever the default is.

Regards

@dukex

Somethings about it?

@mjackson

@L2G I'm with you -- can't believe this hasn't been done yet. :) Is there any hang up with this change? Or can it be applied as is?

@byroot byroot Add keep-alive support
For ease of implementation it rely on the excellent net-http-persistent.

Persistent connections are now the default, but can be turned off globaly with
```ruby
RestClient.persistent = false
```
Or on a request basis by passing `:persistent => false`

If you are not confident with making persistent connections the default you can
easily revert it by removing the `@persistent = true` line in `restclient.rb`.
The test suite will pass whatever the default is.
af5ceb0
@byroot

@mjijackson I've just rebased it. And yes it's ready to merge.

@byroot

Oh, and I use it in production since 3 months against Stripe API, it works like a charm and provide nice speed improvements.

@duncan-bayne

Please, could someone merge this? Without it, RestClient is useless for my needs :(

@hydrozen

Yeah, I could use the keep-alive option myself too with couchrest. Merging would be great!

@jesseangell

+1 -- this should be merged! It's extremely painful using RESTful services over SSL without persistent connections.

@tony-spataro-rs

+1 again for merging this pull request; I badly need persistent HTTP connections and I DON'T want to fork rest-client (or roll my own!)

@duncan-bayne

@tony-spataro-rs - I've forked rest-client from the pull request branch. In your Gemfile you can do:

gem 'rest-client', :github => 'duncan-bayne/rest-client', :branch => 'feature-keep-alive'

Although note that I haven't been maintaining it in terms of merging back from this project. YMMV. No warranties. Santa might eat your puppies. Etc.

It does work well enough for me though.

@tony-spataro-rs
@ab
Owner
ab commented

Hi all, I'm looking to get this merged soon. But I don't think we should make it default in a minor release. There are a number of areas where Net::HTTP::Persistent provides a different API from Net::HTTP in ways that could be very surprising: in the SSL behavior, in the exceptions raised (it rescues things like Errno::ECONNREFUSED and raises Net::HTTP::Persistent::Error instead).

@byroot

@ab no problem, you just need to remove this line: https://github.com/rest-client/rest-client/pull/171/files#diff-acdc459e7a74c777e18f314848bc93b4R101

Do you need a rebase?

@ab
Owner
ab commented

Got it, thanks! There are going to be a bunch of other merge conflicts with the SSL stuff I'm working on, so I can take care of doing the rebase.

@mikhailov

So it looks like persistent becoms default, has it merged in stable branch yet?

@ab ab modified the milestone: 1.8.0, 1.7.0
@cacofonix

@ab Any particular reason you held off on merging this? Alternative solution?

@ab ab removed the ready label
@ab
Owner
ab commented

This is still on my mind, but I'm not yet going to be able to get to this in the next release. The blocker is that it introduces major inconsistency in the exceptions raised / API / expected behavior between when persistence is enabled vs. not.

Ideally we would implement keepalive support in a way that does not change the API.

@ab ab modified the milestone: 2.1.x, 1.8.0
@byroot

Since ruby 2.0, the net/http in the stdlib support keep alive out of the box. You simply need to set the keep_alive_timeout property.

I no longer use rest-client, so I won't update this PR. But you guys should be able to reimplement this easily without any drawback.

@ab ab self-assigned this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 15, 2013
  1. @byroot

    Add keep-alive support

    byroot authored
    For ease of implementation it rely on the excellent net-http-persistent.
    
    Persistent connections are now the default, but can be turned off globaly with
    ```ruby
    RestClient.persistent = false
    ```
    Or on a request basis by passing `:persistent => false`
    
    If you are not confident with making persistent connections the default you can
    easily revert it by removing the `@persistent = true` line in `restclient.rb`.
    The test suite will pass whatever the default is.
Commits on Nov 25, 2014
  1. @mateomurphy

    Switch to TLSv1 by default

    mateomurphy authored
This page is out of date. Refresh to see the latest.
View
38 Gemfile.lock
@@ -0,0 +1,38 @@
+PATH
+ remote: .
+ specs:
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ net-http-persistent
+ netrc (~> 0.7.7)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ addressable (2.3.3)
+ crack (0.3.2)
+ diff-lcs (1.2.1)
+ mime-types (1.21)
+ net-http-persistent (2.8)
+ netrc (0.7.7)
+ rake (10.0.3)
+ rspec (2.13.0)
+ rspec-core (~> 2.13.0)
+ rspec-expectations (~> 2.13.0)
+ rspec-mocks (~> 2.13.0)
+ rspec-core (2.13.1)
+ rspec-expectations (2.13.0)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.13.0)
+ webmock (1.11.0)
+ addressable (>= 2.2.7)
+ crack (>= 0.3.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rake
+ rest-client!
+ rspec (>= 2.0)
+ webmock (>= 0.9.1)
View
6 lib/restclient.rb
@@ -9,6 +9,8 @@
raise LoadError, "no such file to load -- net/https. Try running apt-get install libopenssl-ruby"
end
+require 'net/http/persistent'
+
require File.dirname(__FILE__) + '/restclient/exceptions'
require File.dirname(__FILE__) + '/restclient/request'
require File.dirname(__FILE__) + '/restclient/abstract_response'
@@ -93,9 +95,11 @@ def self.options(url, headers={}, &block)
end
class << self
- attr_accessor :proxy
+ attr_accessor :proxy, :persistent
end
+ @persistent = true
+
# Setup the log for RestClient calls.
# Value should be a logger but can can be stdout, stderr, or a filename.
# You can also configure logging by the environment variable RESTCLIENT_LOG.
View
40 lib/restclient/request.rb
@@ -30,7 +30,7 @@ class Request
:payload, :user, :password, :timeout, :max_redirects,
:open_timeout, :raw_response, :verify_ssl, :ssl_client_cert,
:ssl_client_key, :ssl_ca_file, :processed_headers, :args,
- :ssl_version
+ :ssl_version, :cert_store, :persistent
def self.execute(args, & block)
new(args).execute(& block)
@@ -56,7 +56,9 @@ def initialize args
@ssl_client_cert = args[:ssl_client_cert] || nil
@ssl_client_key = args[:ssl_client_key] || nil
@ssl_ca_file = args[:ssl_ca_file] || nil
- @ssl_version = args[:ssl_version] || 'SSLv3'
+ @ssl_version = args[:ssl_version] || 'TLSv1'
+ @cert_store = args[:cert_store]
+ @persistent = args.has_key?(:persistent) ? args[:persistent] : RestClient.persistent
@tf = nil # If you are a raw request, this is your tempfile
@max_redirects = args[:max_redirects] || 10
@processed_headers = make_headers headers
@@ -98,15 +100,6 @@ def make_headers user_headers
headers
end
- def net_http_class
- if RestClient.proxy
- proxy_uri = URI.parse(RestClient.proxy)
- Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
- else
- Net::HTTP
- end
- end
-
def net_http_request_class(method)
Net::HTTP.const_get(method.to_s.capitalize)
end
@@ -146,8 +139,11 @@ def process_payload(p=nil, parent_key=nil)
def transmit uri, req, payload, & block
setup_credentials req
- net = net_http_class.new(uri.host, uri.port)
- net.use_ssl = uri.is_a?(URI::HTTPS)
+ proxy = URI.parse(RestClient.proxy) if RestClient.proxy
+ app_name = 'rest-client'
+ app_name += '-persistent' if @persistent
+ net = Net::HTTP::Persistent.new(app_name, proxy)
+
net.ssl_version = @ssl_version
err_msg = nil
if (@verify_ssl == false) || (@verify_ssl == OpenSSL::SSL::VERIFY_NONE)
@@ -163,6 +159,7 @@ def transmit uri, req, payload, & block
end
end
net.cert = @ssl_client_cert if @ssl_client_cert
+ net.cert_store = @cert_store if @cert_store
net.key = @ssl_client_key if @ssl_client_key
net.ca_file = @ssl_ca_file if @ssl_ca_file
net.read_timeout = @timeout if @timeout
@@ -178,14 +175,13 @@ def transmit uri, req, payload, & block
log_request
- net.start do |http|
- if @block_response
- http.request(req, payload ? payload.to_s : nil, & @block_response)
- else
- res = http.request(req, payload ? payload.to_s : nil) { |http_response| fetch_body(http_response) }
- log_response res
- process_result res, & block
- end
+ req.body = payload.to_s if payload
+ if @block_response
+ net.request(uri, req, & @block_response)
+ else
+ res = net.request(uri, req) { |http_response| fetch_body(http_response) }
+ log_response res
+ process_result res, & block
end
rescue OpenSSL::SSL::SSLError => e
if err_msg
@@ -197,6 +193,8 @@ def transmit uri, req, payload, & block
raise RestClient::ServerBrokeConnection
rescue Timeout::Error
raise RestClient::RequestTimeout
+ ensure
+ net.shutdown unless @persistent
end
def setup_credentials(req)
View
1  rest-client.gemspec
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
s.summary = 'Simple HTTP and REST client for Ruby, inspired by microframework syntax for specifying actions.'
s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
+ s.add_runtime_dependency(%q<net-http-persistent>)
s.add_development_dependency(%q<webmock>, [">= 0.9.1"])
s.add_development_dependency(%q<rspec>, [">= 2.0"])
s.add_dependency(%q<netrc>, ["~> 0.7.7"])
View
84 spec/integration/request_spec.rb
@@ -1,35 +1,65 @@
require File.join( File.dirname(File.expand_path(__FILE__)), '../base')
describe RestClient::Request do
- describe "ssl verification" do
- it "is successful with the correct ca_file" do
- request = RestClient::Request.new(
- :method => :get,
- :url => 'https://www.mozilla.com',
- :verify_ssl => OpenSSL::SSL::VERIFY_PEER,
- :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "equifax.crt")
- )
- expect { request.execute }.to_not raise_error
+ shared_examples 'an http client' do
+ describe "ssl verification" do
+ it "is successful with the correct ca_file" do
+ request = RestClient::Request.new(
+ :method => :get,
+ :url => 'https://www.mozilla.com',
+ :verify_ssl => OpenSSL::SSL::VERIFY_PEER,
+ :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "equifax.crt")
+ )
+ expect { request.execute }.to_not raise_error
+ end
+
+ # I don' think this feature is useful anymore (under 1.9.3 at the very least).
+ #
+ # Exceptions in verify_callback are ignored; RestClient has to catch OpenSSL::SSL::SSLError
+ # and either re-throw it as is, or throw SSLCertificateNotVerified
+ # based on the contents of the message field of the original exception
+ #.
+ # The client has to handle OpenSSL::SSL::SSLError exceptions anyway,
+ # why make them handle both OpenSSL *AND* RestClient exceptions???
+ #
+ # also see https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.c#L237
+ it "is unsuccessful with an incorrect ca_file" do
+ request = RestClient::Request.new(
+ :method => :get,
+ :url => 'https://www.mozilla.com',
+ :verify_ssl => OpenSSL::SSL::VERIFY_PEER,
+ :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "verisign.crt"),
+ :cert_store => OpenSSL::X509::Store.new
+ )
+ expect { request.execute }.to raise_error(RestClient::SSLCertificateNotVerified)
+ end
+ end
+ end
+
+ describe 'with keep alive' do
+ before :each do
+ @previous_persistent = RestClient.persistent
+ RestClient.persistent = true
+ end
+
+ after :each do
+ RestClient.persistent = @previous_persistent
end
- # I don' think this feature is useful anymore (under 1.9.3 at the very least).
- #
- # Exceptions in verify_callback are ignored; RestClient has to catch OpenSSL::SSL::SSLError
- # and either re-throw it as is, or throw SSLCertificateNotVerified
- # based on the contents of the message field of the original exception
- #.
- # The client has to handle OpenSSL::SSL::SSLError exceptions anyway,
- # why make them handle both OpenSSL *AND* RestClient exceptions???
- #
- # also see https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.c#L237
- it "is unsuccessful with an incorrect ca_file" do
- request = RestClient::Request.new(
- :method => :get,
- :url => 'https://www.mozilla.com',
- :verify_ssl => OpenSSL::SSL::VERIFY_PEER,
- :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "verisign.crt")
- )
- expect { request.execute }.to raise_error(RestClient::SSLCertificateNotVerified)
+ it_should_behave_like 'an http client'
+ end
+
+ describe 'without keep alive' do
+ before :each do
+ @previous_persistent = RestClient.persistent
+ RestClient.persistent = false
+ end
+
+ after :each do
+ RestClient.persistent = @previous_persistent
end
+
+ it_should_behave_like 'an http client'
end
+
end
View
167 spec/request_spec.rb
@@ -11,14 +11,19 @@
@uri.stub!(:request_uri).and_return('/resource')
@uri.stub!(:host).and_return('some')
@uri.stub!(:port).and_return(80)
+ @uri.stub!(:scheme).and_return('http')
+ @uri.stub!(:body=)
- @net = mock("net::http base")
- @http = mock("net::http connection")
- Net::HTTP.stub!(:new).and_return(@net)
- @net.stub!(:start).and_yield(@http)
- @net.stub!(:use_ssl=)
+ @net = mock("net::http::persistent")
+ Net::HTTP::Persistent.stub!(:new).and_return(@net)
@net.stub!(:verify_mode=)
+ @net.stub!(:ssl_version=)
+ @net.stub!(:shutdown)
RestClient.log = nil
+
+ @req = mock("net::http::request")
+ @req.stub!(:body=)
+
end
it "accept */* mimetype, preferring xml" do
@@ -204,19 +209,19 @@
end
it "transmits the request with Net::HTTP" do
- @http.should_receive(:request).with('req', 'payload')
- @net.should_receive(:ssl_version=).with('SSLv3')
+ @net.should_receive(:request).with(@uri, @req)
+ @net.should_receive(:ssl_version=).with('TLSv1')
@request.should_receive(:process_result)
- @request.transmit(@uri, 'req', 'payload')
+ @request.transmit(@uri, @req, 'payload')
end
describe "payload" do
it "sends nil payloads" do
- @http.should_receive(:request).with('req', nil)
- @net.should_receive(:ssl_version=).with('SSLv3')
+ @net.should_receive(:request).with(@uri, @req)
+ @net.should_receive(:ssl_version=).with('TLSv1')
@request.should_receive(:process_result)
@request.stub!(:response_log)
- @request.transmit(@uri, 'req', nil)
+ @request.transmit(@uri, @req, nil)
end
it "passes non-hash payloads straight through" do
@@ -242,17 +247,17 @@
describe "credentials" do
it "sets up the credentials prior to the request" do
- @http.stub!(:request)
- @net.should_receive(:ssl_version=).with('SSLv3')
+ @net.stub!(:request)
+ @net.should_receive(:ssl_version=).with('TLSv1')
@request.stub!(:process_result)
@request.stub!(:response_log)
@request.stub!(:user).and_return('joe')
@request.stub!(:password).and_return('mypass')
- @request.should_receive(:setup_credentials).with('req')
+ @request.should_receive(:setup_credentials).with(@req)
- @request.transmit(@uri, 'req', nil)
+ @request.transmit(@uri, @req, nil)
end
it "does not attempt to send any credentials if user is nil" do
@@ -272,9 +277,9 @@
end
it "catches EOFError and shows the more informative ServerBrokeConnection" do
- @http.stub!(:request).and_raise(EOFError)
- @net.should_receive(:ssl_version=).with('SSLv3')
- lambda { @request.transmit(@uri, 'req', nil) }.should raise_error(RestClient::ServerBrokeConnection)
+ @net.stub!(:request).and_raise(EOFError)
+ @net.should_receive(:ssl_version=).with('TLSv1')
+ lambda { @request.transmit(@uri, @req, nil) }.should raise_error(RestClient::ServerBrokeConnection)
end
it "class method execute wraps constructor" do
@@ -309,16 +314,76 @@
end
describe "proxy" do
+ before :each do
+ @response = Net::HTTPNoContent.new("", "204", "No Content")
+ @response.stub!(:read_body).and_return(nil)
+ @net.stub!(:request).and_return(@response)
+ end
+
it "creates a proxy class if a proxy url is given" do
RestClient.stub!(:proxy).and_return("http://example.com/")
- @request.net_http_class.proxy_class?.should be_true
+ Net::HTTP::Persistent.should_receive(:new).with(instance_of(String), URI.parse("http://example.com/"))
+
+ @request.transmit(@req, @uri, 'payload')
end
it "creates a non-proxy class if a proxy url is not given" do
- @request.net_http_class.proxy_class?.should be_false
+ Net::HTTP::Persistent.should_receive(:new).with(instance_of(String), nil)
+ @request.transmit(@req, @uri, 'payload')
end
end
+ describe "connection pool" do
+ before :each do
+ @response = Net::HTTPNoContent.new("", "204", "No Content")
+ @response.stub!(:read_body).and_return(nil)
+ @net.stub!(:request).and_return(@response)
+ end
+
+ describe "when persistent connections are disabled" do
+ before :each do
+ @previous_persistent = RestClient.persistent
+ RestClient.persistent = false
+ @request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload')
+ end
+
+ after :each do
+ RestClient.persistent = @previous_persistent
+ end
+
+ it "use 'rest-client' pool" do
+ Net::HTTP::Persistent.should_receive(:new).with('rest-client', nil)
+ @request.transmit(@req, @uri, 'payload')
+ end
+
+ it "automatically close connections" do
+ @net.should_receive(:shutdown)
+ @request.transmit(@req, @uri, 'payload')
+ end
+ end
+
+ describe "when persistent connections are enabled" do
+ before :each do
+ @previous_persistent = RestClient.persistent
+ RestClient.persistent = true
+ @request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload')
+ end
+
+ after :each do
+ RestClient.persistent = @previous_persistent
+ end
+
+ it "use 'rest-client' pool" do
+ Net::HTTP::Persistent.should_receive(:new).with('rest-client-persistent', nil)
+ @request.transmit(@req, @uri, 'payload')
+ end
+
+ it "do not close connections" do
+ @net.should_not_receive(:shutdown)
+ @request.transmit(@req, @uri, 'payload')
+ end
+ end
+ end
describe "logging" do
it "logs a get request" do
@@ -381,38 +446,36 @@
describe "timeout" do
it "set read_timeout" do
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :timeout => 123, :ssl_version => 'SSLv3')
- @http.stub!(:request)
+ @net.stub!(:request)
@request.stub!(:process_result)
@request.stub!(:response_log)
@net.should_receive(:read_timeout=).with(123)
@net.should_receive(:ssl_version=).with('SSLv3')
- @request.transmit(@uri, 'req', nil)
+ @request.transmit(@uri, @req, nil)
end
it "set open_timeout" do
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :open_timeout => 123, :ssl_version => 'SSLv3')
- @http.stub!(:request)
+ @net.stub!(:request)
@request.stub!(:process_result)
@request.stub!(:response_log)
@net.should_receive(:open_timeout=).with(123)
@net.should_receive(:ssl_version=).with('SSLv3')
- @request.transmit(@uri, 'req', nil)
+ @request.transmit(@uri, @req, nil)
end
end
describe "ssl" do
it "uses SSL when the URI refers to a https address" do
- @uri.stub!(:is_a?).with(URI::HTTPS).and_return(true)
- @net.should_receive(:use_ssl=).with(true)
- @net.should_receive(:ssl_version=).with('SSLv3')
- @http.stub!(:request)
+ @net.should_receive(:ssl_version=).with('TLSv1')
+ @net.stub!(:request)
@request.stub!(:process_result)
@request.stub!(:response_log)
- @request.transmit(@uri, 'req', 'payload')
+ @request.transmit(@uri, @req, 'payload')
end
it "should default to not verifying ssl certificates" do
@@ -421,21 +484,21 @@
it "should set net.verify_mode to OpenSSL::SSL::VERIFY_NONE if verify_ssl is false" do
@net.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
- @net.should_receive(:ssl_version=).with('SSLv3')
- @http.stub!(:request)
+ @net.should_receive(:ssl_version=).with('TLSv1')
+ @net.stub!(:request)
@request.stub!(:process_result)
@request.stub!(:response_log)
- @request.transmit(@uri, 'req', 'payload')
+ @request.transmit(@uri, @req, 'payload')
end
it "should not set net.verify_mode to OpenSSL::SSL::VERIFY_NONE if verify_ssl is true" do
@request = RestClient::Request.new(:method => :put, :url => 'https://some/resource', :payload => 'payload', :verify_ssl => true, :ssl_version => 'SSLv3')
@net.should_not_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
@net.should_receive(:ssl_version=).with('SSLv3')
- @http.stub!(:request)
+ @net.stub!(:request)
@request.stub!(:process_result)
@request.stub!(:response_log)
- @request.transmit(@uri, 'req', 'payload')
+ @request.transmit(@uri, @req, 'payload')
end
it "should set net.verify_mode to the passed value if verify_ssl is an OpenSSL constant" do
@@ -448,10 +511,10 @@
@net.should_receive(:verify_mode=).with(mode)
@net.should_receive(:verify_callback=)
@net.should_receive(:ssl_version=).with('SSLv3')
- @http.stub!(:request)
+ @net.stub!(:request)
@request.stub!(:process_result)
@request.stub!(:response_log)
- @request.transmit(@uri, 'req', 'payload')
+ @request.transmit(@uri, @req, 'payload')
end
it "should default to not having an ssl_client_cert" do
@@ -468,10 +531,10 @@
)
@net.should_receive(:cert=).with("whatsupdoc!")
@net.should_receive(:ssl_version=).with('SSLv3')
- @http.stub!(:request)
+ @net.stub!(:request)
@request.stub!(:process_result)
@request.stub!(:response_log)
- @request.transmit(@uri, 'req', 'payload')
+ @request.transmit(@uri, @req, 'payload')
end
it "should not set the ssl_client_cert if it is not provided" do
@@ -483,10 +546,10 @@
)
@net.should_not_receive(:cert=).with("whatsupdoc!")
@net.should_receive(:ssl_version=).with('SSLv3')
- @http.stub!(:request)
+ @net.stub!(:request)
@request.stub!(:process_result)
@request.stub!(:response_log)
- @request.transmit(@uri, 'req', 'payload')
+ @request.transmit(@uri, @req, 'payload')
end
it "should default to not having an ssl_client_key" do
@@ -503,10 +566,10 @@
)
@net.should_receive(:key=).with("whatsupdoc!")
@net.should_receive(:ssl_version=).with('SSLv3')
- @http.stub!(:request)
+ @net.stub!(:request)
@request.stub!(:process_result)
@request.stub!(:response_log)
- @request.transmit(@uri, 'req', 'payload')
+ @request.transmit(@uri, @req, 'payload')
end
it "should not set the ssl_client_key if it is not provided" do
@@ -518,10 +581,10 @@
)
@net.should_not_receive(:key=).with("whatsupdoc!")
@net.should_receive(:ssl_version=).with('SSLv3')
- @http.stub!(:request)
+ @net.stub!(:request)
@request.stub!(:process_result)
@request.stub!(:response_log)
- @request.transmit(@uri, 'req', 'payload')
+ @request.transmit(@uri, @req, 'payload')
end
it "should default to not having an ssl_ca_file" do
@@ -538,25 +601,25 @@
)
@net.should_receive(:ca_file=).with("Certificate Authority File")
@net.should_receive(:ssl_version=).with('SSLv3')
- @http.stub!(:request)
+ @net.stub!(:request)
@request.stub!(:process_result)
@request.stub!(:response_log)
- @request.transmit(@uri, 'req', 'payload')
+ @request.transmit(@uri, @req, 'payload')
end
it "should not set the ssl_ca_file if it is not provided" do
@request = RestClient::Request.new(
:method => :put,
:url => 'https://some/resource',
- :ssl_version => 'TSLv1',
+ :ssl_version => 'TLSv1',
:payload => 'payload'
)
@net.should_not_receive(:ca_file=).with("Certificate Authority File")
- @net.should_receive(:ssl_version=).with('TSLv1')
- @http.stub!(:request)
+ @net.should_receive(:ssl_version=).with('TLSv1')
+ @net.stub!(:request)
@request.stub!(:process_result)
@request.stub!(:response_log)
- @request.transmit(@uri, 'req', 'payload')
+ @request.transmit(@uri, @req, 'payload')
end
end
@@ -569,9 +632,9 @@
)
net_http_res = Net::HTTPNoContent.new("", "204", "No Content")
net_http_res.stub!(:read_body).and_return(nil)
- @http.should_receive(:request).and_return(@request.fetch_body(net_http_res))
+ @net.should_receive(:request).and_return(@request.fetch_body(net_http_res))
@net.should_receive(:ssl_version=).with('SSLv3')
- response = @request.transmit(@uri, 'req', 'payload')
+ response = @request.transmit(@uri, @req, 'payload')
response.should_not be_nil
response.code.should == 204
end
Something went wrong with that request. Please try again.