stricter timeout on neopets gateway requests

This commit is contained in:
Emi Matchu 2012-09-29 14:02:11 -05:00
parent ddec043209
commit 2016216d42

View file

@ -1,3 +1,5 @@
require 'timeout'
module RocketAMF
class RemoteGateway
class Request
@ -16,12 +18,14 @@ module RocketAMF
req = Net::HTTP::Post.new(uri.path)
req.body = data
begin
http = Net::HTTP.new(uri.host, uri.port)
http.read_timeout = options[:timeout] if options[:timeout]
res = http.request(req)
rescue Exception => e
raise ConnectionError, e.message
res = nil
if options[:timeout]
Timeout.timeout(options[:timeout], ConnectionError) do
res = send_request(uri, req)
end
else
res = send_request(uri, req)
end
if res.is_a?(Net::HTTPSuccess)
@ -69,6 +73,15 @@ module RocketAMF
message.body = @params
message
end
def send_request(uri, req)
begin
http = Net::HTTP.new(uri.host, uri.port)
return http.request(req)
rescue Exception => e
raise ConnectionError, e.message
end
end
end
class ConnectionError < RuntimeError