]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
httputil: don't fail when b0rked servers put the charset in the content-encoding
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 7 Jul 2008 21:14:24 +0000 (23:14 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 7 Jul 2008 21:17:40 +0000 (23:17 +0200)
lib/rbot/core/utils/httputil.rb

index 9df8fc2cfacfcb90680b9335797a1990139402d9..ae16416d4e15dc52228d5a4509833b7ab574fea5 100644 (file)
@@ -109,7 +109,16 @@ module ::Net
           # TODO
           # debug "full inflation failed (#{e}), trying to recover as much as possible"
         end
+      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
+        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}"
+        return str
       else
+        debug self.to_hash
         raise "Unhandled content encoding #{method}"
       end
     end