Skip to content

Instantly share code, notes, and snippets.

@ramtiga
Created November 15, 2012 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramtiga/4076135 to your computer and use it in GitHub Desktop.
Save ramtiga/4076135 to your computer and use it in GitHub Desktop.
Http request
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