Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #92 from jamescook/allow_http_timeout

Configurable HTTP timeout
  • Loading branch information...
commit 18b3c8b68142d799d9ac05f8eff47b8517ce5d01 2 parents 2d60053 + bb95e30
james cook authored
View
5 lib/garb.rb
@@ -58,6 +58,11 @@ module Garb
class << self
attr_accessor :proxy_address, :proxy_port, :proxy_user, :proxy_password
+ attr_writer :read_timeout
+ end
+
+ def read_timeout
+ @read_timeout || 60
end
def to_google_analytics(thing)
View
4 lib/garb/request/authentication.rb
@@ -27,6 +27,7 @@ def uri
def send_request(ssl_mode)
http = Net::HTTP.new(uri.host, uri.port, Garb.proxy_address, Garb.proxy_port)
+ http.read_timeout = Garb.read_timeout
http.use_ssl = true
http.verify_mode = ssl_mode
@@ -41,6 +42,7 @@ def send_request(ssl_mode)
def build_request
post = Net::HTTP::Post.new(uri.path)
+ post.read_timeout = Garb.read_timeout
post.set_form_data(parameters)
post
end
@@ -52,4 +54,4 @@ def auth_token(opts={})
end
end
-end
View
7 test/unit/garb/request/authentication_test.rb
@@ -38,6 +38,7 @@ class AuthenticationTest < MiniTest::Unit::TestCase
response = mock {|m| m.expects(:is_a?).with(Net::HTTPOK).returns(true) }
http = mock do |m|
+ m.expects(:read_timeout=).with(Garb.read_timeout)
m.expects(:use_ssl=).with(true)
m.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
m.expects(:ca_file=).with(CA_CERT_FILE)
@@ -55,6 +56,7 @@ class AuthenticationTest < MiniTest::Unit::TestCase
response = mock {|m| m.expects(:is_a?).with(Net::HTTPOK).returns(true) }
http = mock do |m|
+ m.expects(:read_timeout=).with(Garb.read_timeout)
m.expects(:use_ssl=).with(true)
m.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
m.expects(:request).with('post').yields(response)
@@ -71,6 +73,7 @@ class AuthenticationTest < MiniTest::Unit::TestCase
post = mock
post.expects(:set_form_data).with(params)
+ post.expects(:read_timeout=).with(Garb.read_timeout)
Net::HTTP::Post.expects(:new).with('/accounts/ClientLogin').returns(post)
@@ -107,6 +110,7 @@ class AuthenticationTest < MiniTest::Unit::TestCase
http = stub do |s|
s.stubs(:use_ssl=)
+ s.expects(:read_timeout=).with(Garb.read_timeout)
s.stubs(:verify_mode=)
s.stubs(:request).yields(response)
end
@@ -124,6 +128,7 @@ class AuthenticationTest < MiniTest::Unit::TestCase
response = stub {|s| s.stubs(:is_a?).returns(true) }
http = mock do |m|
+ m.stubs(:read_timeout=)
m.stubs(:use_ssl=)
m.stubs(:verify_mode=)
m.stubs(:request).yields(response)
@@ -139,4 +144,4 @@ class AuthenticationTest < MiniTest::Unit::TestCase
end
end
end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.