Take the 2-minute tour ×

How do you specify a longer timeout for ruby's http.get?

Here's the context:

def downloadImage(domain, source, dest)
  # e.g. domain: "static.flickr.com"
  #      source: "/00/md5hashcode.jpg"

  puts("Downloading: #{domain}#{source}")

  Net::HTTP.start(domain) { |http|
    resp = http.get(source)
    open(dest, "wb") { |file|

My requests keep timing out, what's the solution/workaround?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Use the read_timeout method, in seconds. Example:

http.read_timeout = 500
share|improve this answer
That looks relevant! Where does it go? I tried putting it right before the line: resp = http.get(source), but I'm still getting the same error. –  dsg Feb 8 '11 at 22:16
Ah, actually, I think I have a different error. This should work. Thanks. –  dsg Feb 8 '11 at 22:18

Your Answer


