diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-04-11 22:43:00 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-04-11 22:43:00 +0000 |
commit | f73a5f3e63b6c68fb04e3d58f97e500bfdd93f51 (patch) | |
tree | 926be7b28410366cf5f4651b5d543f7d379742b7 /lib/rbot | |
parent | 8985c8f3e655ba1aef4166e4247696fed3d20e9c (diff) |
HttpUtil: decompress gzipped body in partial_body too; whitespace cleanup too
Diffstat (limited to 'lib/rbot')
-rw-r--r-- | lib/rbot/core/utils/httputil.rb | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/lib/rbot/core/utils/httputil.rb b/lib/rbot/core/utils/httputil.rb index e0f93953..b4219f66 100644 --- a/lib/rbot/core/utils/httputil.rb +++ b/lib/rbot/core/utils/httputil.rb @@ -26,9 +26,9 @@ end require 'stringio' require 'zlib' -module ::Net - class HTTPResponse - attr_accessor :no_cache +module ::Net + class HTTPResponse + attr_accessor :no_cache if !instance_methods.include?('raw_body') alias :raw_body :body end @@ -88,22 +88,22 @@ module ::Net return self.body_to_utf(self.decompress_body(self.raw_body)) end - # Read chunks from the body until we have at least _size_ bytes, yielding - # the partial text at each chunk. Return the partial body. - def partial_body(size=0, &block) + # Read chunks from the body until we have at least _size_ bytes, yielding + # the partial text at each chunk. Return the partial body. + def partial_body(size=0, &block) self.no_cache = true - partial = String.new + partial = String.new - self.read_body { |chunk| - partial << chunk - yield self.body_to_utf(partial) if block_given? - break if size and size > 0 and partial.length >= size - } + self.read_body { |chunk| + partial << chunk + yield self.body_to_utf(self.decompress_body(partial)) if block_given? + break if size and size > 0 and partial.length >= size + } - return self.body_to_utf(partial) - end - end + return self.body_to_utf(self.decompress_body(partial)) + end + end end Net::HTTP.version_1_2 @@ -244,12 +244,12 @@ class HttpUtil 'Accept-Encoding' => 'gzip;q=1, identity;q=0.8, *;q=0.2', 'User-Agent' => "rbot http util #{$version} (http://linuxbrit.co.uk/rbot/)" - } + } debug "starting http cache cleanup timer" @timer = @bot.timer.add(300) { self.remove_stale_cache unless @bot.config['http.no_expire_cache'] } - end + end def cleanup debug 'stopping http cache cleanup timer' @@ -305,7 +305,7 @@ class HttpUtil # proxying based on the bot's proxy configuration. # This will include per-url proxy configuration based on the bot config # +http_proxy_include/exclude+ options. - + def get_proxy(uri, options = {}) opts = { :read_timeout => 10, @@ -444,7 +444,7 @@ class HttpUtil return handle_response(uri, cached.response, opts, &block) end end - + headers = @headers.dup.merge(opts[:headers] || {}) headers['Range'] = opts[:range] if opts[:range] |