summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordmitry kim <jason@nichego.net>2008-03-23 02:12:04 +0300
committerdmitry kim <jason@nichego.net>2008-03-23 02:12:04 +0300
commit45fe7c191789f7cdc7def283be2551b0c28354dd (patch)
treeb9f2b1a98caac235ffe8305336fe166b4222e853
parent8b57372691904b7d307eec65f0491bf2a88f1f48 (diff)
* httputil: avoid double read in partial_body
-rw-r--r--lib/rbot/core/utils/httputil.rb19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/rbot/core/utils/httputil.rb b/lib/rbot/core/utils/httputil.rb
index 3d4133e0..573c6aca 100644
--- a/lib/rbot/core/utils/httputil.rb
+++ b/lib/rbot/core/utils/httputil.rb
@@ -126,14 +126,21 @@ module ::Net
# the partial text at each chunk. Return the partial body.
def partial_body(size=0, &block)
- self.no_cache = true
partial = String.new
- self.read_body { |chunk|
- partial << chunk
+ if @read
+ debug "using body() as partial"
+ partial = self.body
yield self.body_to_utf(self.decompress_body(partial)) if block_given?
- break if size and size > 0 and partial.length >= size
- }
+ else
+ debug "disabling cache"
+ self.no_cache = true
+ 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
+ }
+ end
return self.body_to_utf(self.decompress_body(partial))
end
@@ -629,7 +636,7 @@ class HttpUtil
# _uri_:: uri to query (URI object or String)
# _nbytes_:: number of bytes to get
#
- # Partia GET request, returns (if possible) the first _nbytes_ bytes of the
+ # Partial GET request, returns (if possible) the first _nbytes_ bytes of the
# response body, following redirs and caching if requested, yielding the
# actual response(s) to the optional block. See get_response for details on
# the supported _options_