aboutsummaryrefslogtreecommitdiffstats
path: root/lib/plum/client/response.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plum/client/response.rb')
-rw-r--r--lib/plum/client/response.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/plum/client/response.rb b/lib/plum/client/response.rb
index a091c7a..32a3d30 100644
--- a/lib/plum/client/response.rb
+++ b/lib/plum/client/response.rb
@@ -6,9 +6,9 @@ module Plum
attr_reader :headers
# @api private
- def initialize(auto_decode: true, **options, &on_headers)
+ def initialize(session, auto_decode: true, **options, &on_headers)
+ @session = session
@headers = nil
- @body = Queue.new
@finished = false
@failed = false
@body = []
@@ -48,6 +48,7 @@ module Plum
raise ArgumentError, "block must be given" unless block_given?
@on_headers = block
yield self if @headers
+ self
end
# Set callback that will be called when received a chunk of response body.
@@ -60,6 +61,7 @@ module Plum
@body.each(&block)
@body.clear
end
+ self
end
# Set callback that will be called when the response finished.
@@ -70,6 +72,7 @@ module Plum
else
@on_finish = block
end
+ self
end
# Returns the complete response body. Use #each_body instead if the body can be very large.
@@ -80,6 +83,11 @@ module Plum
@body.join
end
+ def join
+ @session.succ until (@finished || @failed)
+ self
+ end
+
private
# internal: set headers and setup decoder
def set_headers(headers)