Skip to content

Commit

Permalink
allow disabling the timeouts by passing -1. Closes rest-client#85
Browse files Browse the repository at this point in the history
  • Loading branch information
archiloque committed Aug 22, 2011
1 parent f3026e4 commit a3d0563
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions history.md
Expand Up @@ -3,6 +3,7 @@
- RFC6265 requires single SP after ';' for separating parameters pairs in the 'Cookie:' header (patch provided by Hiroshi Nakamura)
- enable url parameters for all actions
- detect file parameters in arrays
- allow disabling the timeouts by passing -1 (patch provided by Sven Böhm)

# 1.6.4

Expand Down
12 changes: 8 additions & 4 deletions lib/restclient/request.rb
Expand Up @@ -20,7 +20,7 @@ module RestClient
# * :raw_response return a low-level RawResponse instead of a Response
# * :max_redirects maximum number of redirections (default to 10)
# * :verify_ssl enable ssl verification, possible values are constants from OpenSSL::SSL
# * :timeout and :open_timeout
# * :timeout and :open_timeout passing in -1 will disable the timeout by setting the corresponding net timeout values to nil
# * :ssl_client_cert, :ssl_client_key, :ssl_ca_file
class Request

Expand Down Expand Up @@ -69,14 +69,14 @@ def process_url_params url, headers
url_params = {}
headers.delete_if do |key, value|
if 'params' == key.to_s.downcase && value.is_a?(Hash)
url_params .merge! value
url_params.merge! value
true
else
false
end
end
unless url_params .empty?
query_string = url_params .collect { |k, v| "#{k.to_s}=#{CGI::escape(v.to_s)}" }.join('&')
unless url_params.empty?
query_string = url_params.collect { |k, v| "#{k.to_s}=#{CGI::escape(v.to_s)}" }.join('&')
url + "?#{query_string}"
else
url
Expand Down Expand Up @@ -157,6 +157,10 @@ def transmit uri, req, payload, & block
net.read_timeout = @timeout if @timeout
net.open_timeout = @open_timeout if @open_timeout

# disable the timeout if the timeout value is -1
net.read_timeout = nil if @timeout == -1
net.out_timeout = nil if @open_timeout == -1

RestClient.before_execution_procs.each do |before_proc|
before_proc.call(req, args)
end
Expand Down

0 comments on commit a3d0563

Please sign in to comment.