summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authordmitry kim <jason@nichego.net>2008-12-10 21:42:27 +0300
committerdmitry kim <jason@nichego.net>2008-12-10 21:42:27 +0300
commit3fd359173f62f7ba571f83bd56b515a79d8287e3 (patch)
tree015612a31e5e469c35d7fb5d75f3bce29326784c /lib/rbot
parentfd73f164176d637239714ed7a362a3d4d6fde4fc (diff)
* (httputil) provide an informative error message for non-http urls
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/core/utils/httputil.rb58
1 files changed, 33 insertions, 25 deletions
diff --git a/lib/rbot/core/utils/httputil.rb b/lib/rbot/core/utils/httputil.rb
index 8272057a..9792e0c5 100644
--- a/lib/rbot/core/utils/httputil.rb
+++ b/lib/rbot/core/utils/httputil.rb
@@ -482,6 +482,14 @@ class HttpUtil
#
def get_response(uri_or_s, options = {}, &block) # :yields: resp
uri = uri_or_s.kind_of?(URI) ? uri_or_s : URI.parse(uri_or_s.to_s)
+ unless URI::HTTP === uri
+ if uri.scheme
+ raise "#{uri.scheme.inspect} URI scheme is not supported"
+ else
+ raise "don't know what to do with #{uri.to_s.inspect}"
+ end
+ end
+
opts = {
:max_redir => @bot.config['http.max_redir'],
:yield => :final,
@@ -547,35 +555,35 @@ class HttpUtil
debug "prepared request: #{req.to_hash.inspect}"
begin
- get_proxy(uri, opts).start do |http|
- http.request(req) do |resp|
- resp['x-rbot-location'] = uri.to_s
- if Net::HTTPNotModified === resp
- debug "not modified"
- begin
- cached.revalidate(resp)
- rescue Exception => e
- error e
- end
- debug "reusing cached"
- resp = cached.response
- elsif Net::HTTPServerError === resp || Net::HTTPClientError === resp
- debug "http error, deleting cached obj" if cached
- @cache.delete(cache_key)
- elsif opts[:cache]
- begin
- return handle_response(uri, resp, opts, &block)
- ensure
- if cached = CachedObject.maybe_new(resp) rescue nil
- debug "storing to cache"
- @cache[cache_key] = cached
+ get_proxy(uri, opts).start do |http|
+ http.request(req) do |resp|
+ resp['x-rbot-location'] = uri.to_s
+ if Net::HTTPNotModified === resp
+ debug "not modified"
+ begin
+ cached.revalidate(resp)
+ rescue Exception => e
+ error e
+ end
+ debug "reusing cached"
+ resp = cached.response
+ elsif Net::HTTPServerError === resp || Net::HTTPClientError === resp
+ debug "http error, deleting cached obj" if cached
+ @cache.delete(cache_key)
+ elsif opts[:cache]
+ begin
+ return handle_response(uri, resp, opts, &block)
+ ensure
+ if cached = CachedObject.maybe_new(resp) rescue nil
+ debug "storing to cache"
+ @cache[cache_key] = cached
+ end
end
+ return ret
end
- return ret
+ return handle_response(uri, resp, opts, &block)
end
- return handle_response(uri, resp, opts, &block)
end
- end
rescue Exception => e
error e
raise e.message