]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
httputil: support Content-Encoding: deflate
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 29 Oct 2007 20:48:36 +0000 (20:48 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 29 Oct 2007 20:48:36 +0000 (20:48 +0000)
lib/rbot/core/utils/httputil.rb

index d9b88839716d2a20f87611637ca7c50a454e1a89..dc3b6b99d7e882a6fb3e38759b695f1768301513 100644 (file)
@@ -101,6 +101,18 @@ module ::Net
           end
           return ret
         end
+      when 'deflate'
+        debug "inflating body"
+        # From http://www.koders.com/ruby/fid927B4382397E5115AC0ABE21181AB5C1CBDD5C17.aspx?s=thread: 
+        # -MAX_WBITS stops zlib from looking for a zlib header
+        inflater = Zlib::Inflate.new(-Zlib::MAX_WBITS)
+        begin
+          return inflater.inflate(str)
+        rescue Zlib::Error => e
+          raise e
+          # TODO
+          # debug "full inflation failed (#{e}), trying to recover as much as possible"
+        end
       else
         raise "Unhandled content encoding #{method}"
       end