From: Tanaka Akira Date: 2005-05-07T23:32:50+09:00 Subject: Re: [ ruby-Bugs-1878 ] No way to change socket timeout on opened URI In article <200505052255.j45MtVam031547@rubyforge.org>, noreply@rubyforge.org writes: > open-uri is very handy, but as far as I can tell I can't change the read timeout > on the underlying socket. I end up having to hack a workaround into Net::HTTP > to allow me to set a timeout on its instances before opening the URI. Does adding :read_timeout option solve the problem? Index: lib/open-uri.rb =================================================================== RCS file: /src/ruby/lib/open-uri.rb,v retrieving revision 1.36 diff -u -p -r1.36 open-uri.rb --- lib/open-uri.rb 19 Feb 2005 15:53:23 -0000 1.36 +++ lib/open-uri.rb 7 May 2005 14:26:52 -0000 @@ -97,6 +97,7 @@ module OpenURI :progress_proc => true, :content_length_proc => true, :http_basic_authentication => true, + :read_timeout => true, } def OpenURI.check_options(options) # :nodoc: @@ -237,6 +238,9 @@ module OpenURI store.set_default_paths http.cert_store = store end + if options.include? :read_timeout + http.read_timeout = options[:read_timeout] + end header = {} options.each {|k, v| header[k] = v if String === k } @@ -518,6 +522,13 @@ module OpenURI # :progress_proc => lambda {|s| # pbar.set s if pbar # }) {|f| ... } + # + # [:read_timeout] + # Synopsis: + # :read_timeout=>nil (no timeout) + # :read_timeout=>10 (10 second) + # + # :read_timeout option specifies a timeout of read for http connections. # # OpenURI::OpenRead#open returns an IO like object if block is not given. # Otherwise it yields the IO object and return the value of the block. -- Tanaka Akira