From 5a1e2b5d174ba11073ff122530b29488185366c0 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 15 Apr 2007 01:44:40 +0000 Subject: HttpUtil: fix gunzipping with partial content; and debug response in url plugin earlier --- lib/rbot/core/utils/httputil.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib/rbot') diff --git a/lib/rbot/core/utils/httputil.rb b/lib/rbot/core/utils/httputil.rb index b4219f66..3c949686 100644 --- a/lib/rbot/core/utils/httputil.rb +++ b/lib/rbot/core/utils/httputil.rb @@ -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 -- cgit v1.2.3