Setting a short HTTP GET timeout

Hi guys,

I’m doing a web crawl on our internal network. I need to execute an
HTTP GET cmd to a REST service, and would like the call to timeout
after, say, 3 seconds - since not all IP’s will respond to the call, and
those that do will respond almost immediately. I’ve tried several
different ways, after scouring the web, but no joy.

The most promising efforts (that don’t work) are:

Setting the read/open timeout values:

http = Net::HTTP.new(server, 80)
http.read_timeout=2
http.open_timeout=2
response = http.request(Net::HTTP::Get.new("/query"))

and the Timeout object:

http = Net::HTTP.new(server, 80)
response = nil
timeout(5) {
response = http.request(Net::HTTP::Get.new("/query")
)#end timeout

In both cases, it waits until the http.request line times out - 20 or 30
seconds. BTW, I’ve also tried the rest-client library, etc. Very
frustrating…

Thanks much,
Butch>