summaryrefslogtreecommitdiff
path: root/rbot/httputil.rb
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2005-07-27 16:32:32 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2005-07-27 16:32:32 +0000
commit2a96c9198c1f6e13407d0999083f6ce5e0bc06fa (patch)
treeb3b9247d275d9b554665bc22884104d266d2e757 /rbot/httputil.rb
parent21949774b91eaec6ecde4eaa8ad121e2c0a36b87 (diff)
move rbot into lib - still rearranging for packaging/installation
Diffstat (limited to 'rbot/httputil.rb')
-rw-r--r--rbot/httputil.rb88
1 files changed, 0 insertions, 88 deletions
diff --git a/rbot/httputil.rb b/rbot/httputil.rb
deleted file mode 100644
index ff3216a6..00000000
--- a/rbot/httputil.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-module Irc
-
-require 'net/http'
-Net::HTTP.version_1_2
-
-# class for making http requests easier (mainly for plugins to use)
-# this class can check the bot proxy configuration to determine if a proxy
-# needs to be used, which includes support for per-url proxy configuration.
-class HttpUtil
- def initialize(bot)
- @bot = bot
- @headers = {
- 'User-Agent' => "rbot http util #{$version} (http://linuxbrit.co.uk/rbot/)",
- }
- end
-
- # uri:: Uri to create a proxy for
- #
- # return a net/http Proxy object, which is configured correctly for
- # proxying based on the bot's proxy configuration.
- # This will include per-url proxy configuration based on the bot config
- # +http_proxy_include/exclude+ options.
- def get_proxy(uri)
- proxy = nil
- if (ENV['http_proxy'])
- proxy = URI.parse ENV['http_proxy']
- end
- if (@bot.config["http_proxy"])
- proxy = URI.parse ENV['http_proxy']
- end
-
- # if http_proxy_include or http_proxy_exclude are set, then examine the
- # uri to see if this is a proxied uri
- if uri
- if @bot.config["http_proxy_exclude"]
- # TODO
- end
- if @bot.config["http_proxy_include"]
- end
- end
-
- proxy_host = nil
- proxy_port = nil
- proxy_user = nil
- proxy_pass = nil
- if @bot.config["http_proxy_user"]
- proxy_user = @bot.config["http_proxy_user"]
- if @bot.config["http_proxy_pass"]
- proxy_pass = @bot.config["http_proxy_pass"]
- end
- end
- if proxy
- proxy_host = proxy.host
- proxy_port = proxy.port
- end
-
- return Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port, proxy_user, proxy_port)
- end
-
- # uri:: uri to query (Uri object)
- # readtimeout:: timeout for reading the response
- # opentimeout:: timeout for opening the connection
- #
- # simple get request, returns response body if the status code is 200 and
- # the request doesn't timeout.
- def get(uri, readtimeout=10, opentimeout=5)
- proxy = get_proxy(uri)
- proxy.open_timeout = opentimeout
- proxy.read_timeout = readtimeout
-
- begin
- proxy.start() {|http|
- resp = http.get(uri.request_uri(), @headers)
- if resp.code == "200"
- return resp.body
- else
- puts "HttpUtil.get return code #{resp.code} #{resp.body}"
- end
- return nil
- }
- rescue StandardError, Timeout::Error => e
- $stderr.puts "HttpUtil.get exception: #{e}, while trying to get #{uri}"
- end
- return nil
- end
-end
-
-end