From 84e53ad77fae1fd7e924986c5f36a04115e13ffc Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 1 Apr 2007 15:04:53 +0000 Subject: httputil: reinstate partial_body --- lib/rbot/core/utils/httputil.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib') diff --git a/lib/rbot/core/utils/httputil.rb b/lib/rbot/core/utils/httputil.rb index 4ce8dcc3..78445abe 100644 --- a/lib/rbot/core/utils/httputil.rb +++ b/lib/rbot/core/utils/httputil.rb @@ -20,6 +20,25 @@ rescue LoadError => e error "Secured HTTP connections will fail" end +module ::Net + class HTTPResponse + # 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) + + partial = String.new + + self.read_body { |chunk| + partial << chunk + yield partial if block_given? + break if size and size > 0 and partial.length >= size + } + + return partial + end + end +end + Net::HTTP.version_1_2 module ::Irc -- cgit v1.2.3