Skip to content

Instantly share code, notes, and snippets.

@toto
Created September 16, 2009 15:16
Show Gist options
  • Save toto/188098 to your computer and use it in GitHub Desktop.
Save toto/188098 to your computer and use it in GitHub Desktop.
Net/HTTP has some serious bugs regarding timeout in JRuby. Therefor it is useful to just use the Java classes to get a reliable timeout
require 'java'
import java.net
import java.io
uri = java.net.URL.new("http://127.0.0.1")
con = uri.openConnection()
con.setConnectTimeout(1000) # in millisecs so this is 1 sec
con.setReadTimeout(1000)
in_reader = java.io.BufferedReader.new(java.io.InputStreamReader.new(con.getInputStream()));
buf = ''
while inputLine = in_reader.readLine do
 buf << inputLine;
end
in_reader.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment