ruby - how to raise a timeout error manually? -


i want test http request. output if timeout.

  begin       url = "#{url}?#{params.to_param}"       net::http.get_response(uri.parse(url))   rescue timeout::error       puts "....."   end 

how raise timeout error manually? or how set shorter timeout number http request?

for http request, should change default timeout number? how long appropriate?

to set timeout use:

http = net::http.new(host_param)  http.read_timeout = 500 

there few types of timeouts can set. docs:

  • open_timeout: number of seconds wait connection open. number may used, including floats fractional seconds. if http object cannot open connection in many seconds, raises net::opentimeout exception. default value nil.

  • read_timeout: number of seconds wait 1 block read (via 1 read(2) call). number may used, including floats fractional seconds. if http object cannot read data in many seconds, raises net::readtimeout exception. default value 60 seconds.

  • ssl_timeout: sets ssl timeout seconds.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -