def get_proxy(uri, options = {})
opts = {
:read_timeout => @bot.config["http.read_timeout"],
:open_timeout => @bot.config["http.open_timeout"]
}.merge(options)
proxy = nil
proxy_host = nil
proxy_port = nil
proxy_user = nil
proxy_pass = nil
if @bot.config["http.use_proxy"]
if (ENV['http_proxy'])
proxy = URI.parse ENV['http_proxy'] rescue nil
end
if (@bot.config["http.proxy_uri"])
proxy = URI.parse @bot.config["http.proxy_uri"] rescue nil
end
if proxy
debug "proxy is set to #{proxy.host} port #{proxy.port}"
if proxy_required(uri)
proxy_host = proxy.host
proxy_port = proxy.port
proxy_user = @bot.config["http.proxy_user"]
proxy_pass = @bot.config["http.proxy_pass"]
end
end
end
h = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port, proxy_user, proxy_port)
h.use_ssl = true if uri.scheme == "https"
h.read_timeout = opts[:read_timeout]
h.open_timeout = opts[:open_timeout]
return h
end