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
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue