stricter timeout on neopets gateway requests
This commit is contained in:
parent
ddec043209
commit
2016216d42
1 changed files with 19 additions and 6 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
require 'timeout'
|
||||||
|
|
||||||
module RocketAMF
|
module RocketAMF
|
||||||
class RemoteGateway
|
class RemoteGateway
|
||||||
class Request
|
class Request
|
||||||
|
@ -16,12 +18,14 @@ module RocketAMF
|
||||||
req = Net::HTTP::Post.new(uri.path)
|
req = Net::HTTP::Post.new(uri.path)
|
||||||
req.body = data
|
req.body = data
|
||||||
|
|
||||||
begin
|
res = nil
|
||||||
http = Net::HTTP.new(uri.host, uri.port)
|
|
||||||
http.read_timeout = options[:timeout] if options[:timeout]
|
if options[:timeout]
|
||||||
res = http.request(req)
|
Timeout.timeout(options[:timeout], ConnectionError) do
|
||||||
rescue Exception => e
|
res = send_request(uri, req)
|
||||||
raise ConnectionError, e.message
|
end
|
||||||
|
else
|
||||||
|
res = send_request(uri, req)
|
||||||
end
|
end
|
||||||
|
|
||||||
if res.is_a?(Net::HTTPSuccess)
|
if res.is_a?(Net::HTTPSuccess)
|
||||||
|
@ -69,6 +73,15 @@ module RocketAMF
|
||||||
message.body = @params
|
message.body = @params
|
||||||
message
|
message
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class ConnectionError < RuntimeError
|
class ConnectionError < RuntimeError
|
||||||
|
|
Loading…
Reference in a new issue