summaryrefslogtreecommitdiff
path: root/lib/custodian/protocol-tests/http.rb
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-14 21:48:31 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-14 21:48:31 +0000
commitec2668b143bf4634621ebc1e93c1666c427fb304 (patch)
tree7ee604638c68b99c7af22106f15ae97381cfdf3e /lib/custodian/protocol-tests/http.rb
parent67ac15a68ab7dee8c0a880c44e8caaaf79b39310 (diff)
Timeout correctly.
Diffstat (limited to 'lib/custodian/protocol-tests/http.rb')
-rwxr-xr-xlib/custodian/protocol-tests/http.rb102
1 files changed, 52 insertions, 50 deletions
diff --git a/lib/custodian/protocol-tests/http.rb b/lib/custodian/protocol-tests/http.rb
index c11e27a..34fc472 100755
--- a/lib/custodian/protocol-tests/http.rb
+++ b/lib/custodian/protocol-tests/http.rb
@@ -113,64 +113,66 @@ class HTTPTest
#
# NOTE: This came from sentinel.
def getURL (uri_str, timeout)
- begin
- uri_str = 'http://' + uri_str unless uri_str.match(/^http/)
- url = URI.parse(uri_str)
- http = Net::HTTP.new(url.host, url.port)
- http.open_timeout = timeout
- http.read_timeout = timeout
-
- if (url.scheme == "https")
- http.use_ssl = true
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
- end
- response = nil
+ timeout( timeout ) do
+ begin
+ uri_str = 'http://' + uri_str unless uri_str.match(/^http/)
+ url = URI.parse(uri_str)
+ http = Net::HTTP.new(url.host, url.port)
+ http.open_timeout = timeout
+ http.read_timeout = timeout
+
+ if (url.scheme == "https")
+ http.use_ssl = true
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ end
- #
- # Ensure we have a trailing "/"
- #
- if ( url.path.empty? )
- url.path = "/"
- end
+ response = nil
- if nil == url.query
- response = http.start { http.get(url.path) }
- else
- response = http.start { http.get("#{url.path}?#{url.query}") }
- end
+ #
+ # Ensure we have a trailing "/"
+ #
+ if ( url.path.empty? )
+ url.path = "/"
+ end
- case response
- when Net::HTTPRedirection
- then
- newURL = response['location'].match(/^http/)?
- response['Location']:uri_str+response['Location']
- return( getURL(newURL, timeout) )
- else
- @status = response.code.to_i
- @body = response.body
- end
+ if nil == url.query
+ response = http.start { http.get(url.path) }
+ else
+ response = http.start { http.get("#{url.path}?#{url.query}") }
+ end
- return true
- rescue Errno::EHOSTUNREACH => ex
- @error = "no route to host"
- return false
- rescue Timeout::Error => ex
- @error = "time out reached"
- return false
- rescue Errno::ECONNREFUSED => ex
- @error = "Connection refused"
- return false
- rescue => ex
- @error = ex
- return false
+ case response
+ when Net::HTTPRedirection
+ then
+ newURL = response['location'].match(/^http/)?
+ response['Location']:uri_str+response['Location']
+ return( getURL(newURL, timeout) )
+ else
+ @status = response.code.to_i
+ @body = response.body
+ end
+
+ return true
+ rescue Errno::EHOSTUNREACH => ex
+ @error = "no route to host"
+ return false
+ rescue Timeout::Error => ex
+ @error = "time out reached"
+ return false
+ rescue Errno::ECONNREFUSED => ex
+ @error = "Connection refused"
+ return false
+ rescue Timeout::Error => e
+ @error = "TIMEOUT: #{e}"
+ return false
+ rescue => ex
+ @error = ex
+ return false
+ end
end
- @error = "Misc failure"
- return false
end
-
-
end