Created
April 13, 2010 17:47
-
-
Save bmarini/364868 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "net/http" | |
http = Net::HTTP.new("example.com") | |
http.open_timeout = 2 | |
http.read_timeout = 3 # Must be greater than open_timeout | |
begin | |
http.start | |
begin | |
http.request_get("/whatever?") do |res| | |
res.read_body | |
end | |
rescue Timeout::Error | |
puts "Timeout due to reading" | |
end | |
rescue Timeout::Error | |
puts "Timeout due to connecting" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment