Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to define open and read timeout individualy #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/xmlrpc/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class Client
#
# If +use_ssl+ is set to +true+, communication over SSL is enabled.
#
# Parameter +timeout+ is the time to wait for a XML-RPC response, defaults to 30.
# Parameter +timeout+ defines the open timeout and read timeout of the
# XML-RPC request. You can set them individually using the methods
# `open_timeout=` and `read_timeout=`
def initialize(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil,
user=nil, password=nil, use_ssl=nil, timeout=nil)

Expand Down Expand Up @@ -215,6 +217,14 @@ def timeout=(new_timeout)
@http.open_timeout = @timeout
end

def open_timeout=(new_timeout)
@http.open_timeout = new_timeout
end

def read_timeout=(new_timeout)
@http.read_timeout = new_timeout
end

# Changes the user for the Basic Authentication header to +new_user+
def user=(new_user)
@user = new_user
Expand Down
16 changes: 16 additions & 0 deletions test/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ def initialize(*args)
end
end

def test_open_timeout=
client = Fake::Client.new 'http://example.org/foo'
assert_equal 30, client.http.open_timeout

client.open_timeout = 10
assert_equal 10, client.http.open_timeout
end

def test_read_timeout=
client = Fake::Client.new 'http://example.org/foo'
assert_equal 30, client.http.read_timeout

client.read_timeout = 20
assert_equal 20, client.http.read_timeout
end

def test_new2_host_path_port
client = Fake::Client.new2 'http://example.org/foo'
host, path, port, *rest = client.args
Expand Down