]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/core/utils/httputil.rb
HttpUtil: fix gunzipping with partial content; and debug response in url plugin earlier
[user/henk/code/ruby/rbot.git] / lib / rbot / core / utils / httputil.rb
index b4219f66f2b8b348b5a11116d2c827cc7b41c400..3c94968658f75d7b28910bb36487ecbf4c933a0c 100644 (file)
@@ -78,7 +78,21 @@ module ::Net
         return str
       when 'gzip', 'x-gzip'
         debug "gunzipping body"
-        return Zlib::GzipReader.new(StringIO.new(str)).read
+        begin
+          return Zlib::GzipReader.new(StringIO.new(str)).read
+        rescue Zlib::Error => e
+          # If we can't unpack the whole stream (e.g. because we're doing a
+          # partial read
+          debug "full gunzipping failed (#{e}), trying to recover as much as possible"
+          ret = ""
+          begin
+            Zlib::GzipReader.new(StringIO.new(str)).each_byte { |byte|
+              ret << byte
+            }
+          rescue
+          end
+          return ret
+        end
       else
         raise "Unhandled content encoding #{method}"
       end