Skip to content

Instantly share code, notes, and snippets.

@bmarini
Created April 13, 2010 17:47
Show Gist options
  • Save bmarini/364868 to your computer and use it in GitHub Desktop.
Save bmarini/364868 to your computer and use it in GitHub Desktop.
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