diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2012-03-03 19:04:34 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2012-03-03 19:04:34 +0100 |
commit | af91a8059f8d8b1bd62b10fd9681dc93c2356d52 (patch) | |
tree | b4ce86f37464fa727857c6266f4d8bbf3c53e308 | |
parent | 71588c22a8e4211123f03a839369dc393c4ee4fc (diff) |
httputil: work (sub-par) without iconv
-rw-r--r-- | lib/rbot/core/utils/httputil.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/rbot/core/utils/httputil.rb b/lib/rbot/core/utils/httputil.rb index e69120be..be5c085a 100644 --- a/lib/rbot/core/utils/httputil.rb +++ b/lib/rbot/core/utils/httputil.rb @@ -10,7 +10,13 @@ require 'resolv' require 'net/http' require 'cgi' -require 'iconv' +begin + require 'iconv' +rescue LoadError => e + error "Couldn't load 'iconv': #{e}" + error "Non-UTF-8 webpages will not be properly supported" +end + begin require 'net/https' rescue LoadError => e @@ -66,6 +72,7 @@ module ::Net def body_to_utf(str) charsets = self.body_charset(str) or return str + return str unless defined? Iconv charsets.reverse_each do |charset| # XXX: this one is really ugly, but i don't know how to make it better @@ -122,7 +129,7 @@ module ::Net when /^(?:iso-8859-\d+|windows-\d+|utf-8|utf8)$/i # B0rked servers (Freshmeat being one of them) sometimes return the charset # in the content-encoding; in this case we assume that the document has - # a standarc content-encoding + # a standard content-encoding old_hsh = self.to_hash self['content-type']= self['content-type']+"; charset="+method.downcase warning "Charset vs content-encoding confusion, trying to recover: from\n#{old_hsh.pretty_inspect}to\n#{self.to_hash.pretty_inspect}" |