Created
November 15, 2012 01:46
-
-
Save ramtiga/4076135 to your computer and use it in GitHub Desktop.
Http request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def http(request) | |
env = ENV['http_proxy'] | |
if env then | |
uri = URI(env) | |
proxy_host, proxy_port = uri.host, uri.port | |
else | |
proxy_host, proxy_port = nil, nil | |
end | |
connection = Net::HTTP::Proxy(proxy_host, proxy_port).new("api.github.com", 443) | |
connection.use_ssl = true | |
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
connection.open_timeout = 10 | |
connection.read_timeout = 10 | |
connection.start do |http| | |
http.request request | |
end | |
rescue Timeout::Error | |
raise "Could not connect to https://api.github.com/" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment