From 3fd359173f62f7ba571f83bd56b515a79d8287e3 Mon Sep 17 00:00:00 2001 From: dmitry kim Date: Wed, 10 Dec 2008 21:42:27 +0300 Subject: * (httputil) provide an informative error message for non-http urls --- lib/rbot/core/utils/httputil.rb | 58 +++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 25 deletions(-) (limited to 'lib/rbot') 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 -- cgit v1.2.3