summaryrefslogtreecommitdiff
path: root/lib/rbot/httputil.rb
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2005-07-30 21:35:57 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2005-07-30 21:35:57 +0000
commitd30940cb5ff75cf7eab81f6a588b3b5297a762ad (patch)
treeb3f0a62c9255b2ecb8a4f2c927bd116e220b0594 /lib/rbot/httputil.rb
parent992ef2edbf3eed7cb1d7c4c22f72cd203aff2aa5 (diff)
Sat Jul 30 22:33:36 BST 2005 Tom Gilbert <tom@linuxbrit.co.uk>
* Config items are now objects, various types are available. * The config wizard will now use registered config items if :wizard is set to true for those items. It will ask questions in the order they were registered. * The config module now works for doing runtime configuration. * misc refactoring
Diffstat (limited to 'lib/rbot/httputil.rb')
-rw-r--r--lib/rbot/httputil.rb51
1 files changed, 26 insertions, 25 deletions
diff --git a/lib/rbot/httputil.rb b/lib/rbot/httputil.rb
index 56de7349..b49a42b1 100644
--- a/lib/rbot/httputil.rb
+++ b/lib/rbot/httputil.rb
@@ -8,15 +8,20 @@ Net::HTTP.version_1_2
# 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
- BotConfig.register('http.proxy', :default => false,
+ BotConfig.register BotConfigBooleanValue.new('http.use_proxy',
+ :default => false, :desc => "should a proxy be used for HTTP requests?")
+ BotConfig.register BotConfigStringValue.new('http.proxy_uri', :default => false,
:desc => "Proxy server to use for HTTP requests (URI, e.g http://proxy.host:port)")
- BotConfig.register('http.proxy_user', :default => false,
+ BotConfig.register BotConfigStringValue.new('http.proxy_user',
+ :default => nil,
:desc => "User for authenticating with the http proxy (if required)")
- BotConfig.register('http.proxy_pass', :default => false,
+ BotConfig.register BotConfigStringValue.new('http.proxy_pass',
+ :default => nil,
:desc => "Password for authenticating with the http proxy (if required)")
- BotConfig.register('http.proxy_include', :type => :array, :default => [],
+ BotConfig.register BotConfigArrayValue.new('http.proxy_include',
+ :default => [],
:desc => "List of regexps to check against a URI's hostname/ip to see if we should use the proxy to access this URI. All URIs are proxied by default if the proxy is set, so this is only required to re-include URIs that might have been excluded by the exclude list. e.g. exclude /.*\.foo\.com/, include bar\.foo\.com")
- BotConfig.register('http.proxy_exclude', :type => :array, :default => [],
+ BotConfig.register BotConfigArrayValue.new('http.proxy_exclude',
:desc => "List of regexps to check against a URI's hostname/ip to see if we should use avoid the proxy to access this URI and access it directly")
def initialize(bot)
@@ -77,31 +82,27 @@ class HttpUtil
# +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 proxy
- debug "proxy is set to #{proxy.uri}"
- proxy = nil unless proxy_required(uri)
- 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"]
+
+ if @bot.config["http.use_proxy"]
+ if (ENV['http_proxy'])
+ proxy = URI.parse ENV['http_proxy']
+ end
+ if (@bot.config["http.proxy_uri"])
+ proxy = URI.parse ENV['http_proxy_uri']
+ end
+ if proxy
+ debug "proxy is set to #{proxy.uri}"
+ 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
- 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)