52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/unirest.rb', line 52
def self.internal_request(http_request, timeout)
http_request.("user-agent", USER_AGENT)
http_request.("accept-encoding", "gzip")
http_response = nil;
begin
case http_request.method
when :get
http_response = RestClient::Request.execute(:method => :get, :url => http_request.url, :headers => http_request., :timeout => timeout)
when :post
http_response = RestClient::Request.execute(:method => :post, :url => http_request.url, :payload => http_request.body, :headers => http_request., :timeout => timeout)
when :put
http_response = RestClient::Request.execute(:method => :put, :url => http_request.url, :payload => http_request.body, :headers => http_request., :timeout => timeout)
when :delete
http_response = RestClient::Request.execute(:method => :delete, :url => http_request.url, :payload => http_request.body, :headers => http_request., :timeout => timeout)
when :patch
http_response = RestClient::Request.execute(:method => :patch, :url => http_request.url, :payload => http_request.body, :headers => http_request., :timeout => timeout)
end
rescue RestClient::RequestTimeout
raise 'Request Timeout'
rescue => e
http_response = e.response
end
return Unirest::HttpResponse.new(http_response)
end
|