6 # class for making http requests easier (mainly for plugins to use)
7 # this class can check the bot proxy configuration to determine if a proxy
8 # needs to be used, which includes support for per-url proxy configuration.
14 # uri:: Uri to create a proxy for
16 # return a net/http Proxy object, which is configured correctly for
17 # proxying based on the bot's proxy configuration.
18 # This will include per-url proxy configuration based on the bot config
19 # +http_proxy_include/exclude+ options.
22 if (ENV['http_proxy'])
23 proxy = URI.parse ENV['http_proxy']
25 if (@bot.config["http_proxy"])
26 proxy = URI.parse ENV['http_proxy']
29 # if http_proxy_include or http_proxy_exclude are set, then examine the
30 # uri to see if this is a proxied uri
32 if @bot.config["http_proxy_exclude"]
35 if @bot.config["http_proxy_include"]
43 if @bot.config["http_proxy_user"]
44 proxy_user = @bot.config["http_proxy_user"]
45 if @bot.config["http_proxy_pass"]
46 proxy_pass = @bot.config["http_proxy_pass"]
50 proxy_host = proxy.host
51 proxy_port = proxy.port
54 return Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port, proxy_user, proxy_port)
57 # uri:: uri to query (Uri object)
58 # readtimeout:: timeout for reading the response
59 # opentimeout:: timeout for opening the connection
61 # simple get request, returns response body if the status code is 200 and
62 # the request doesn't timeout.
63 def get(uri, readtimeout=10, opentimeout=5)
64 proxy = get_proxy(uri)
65 proxy.open_timeout = opentimeout
66 proxy.read_timeout = readtimeout
76 rescue StandardError, Timeout::Error => e
77 $stderr.puts "HttpUtil.get exception: #{e}, while trying to get #{uri}"