aboutsummaryrefslogtreecommitdiffstats
path: root/lib/plum
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plum')
-rw-r--r--lib/plum/client.rb2
-rw-r--r--lib/plum/client/client_session.rb2
-rw-r--r--lib/plum/client/legacy_client_session.rb2
-rw-r--r--lib/plum/client/response.rb12
4 files changed, 13 insertions, 5 deletions
diff --git a/lib/plum/client.rb b/lib/plum/client.rb
index bdbfd72..cb968b4 100644
--- a/lib/plum/client.rb
+++ b/lib/plum/client.rb
@@ -33,7 +33,7 @@ module Plum
@host = host
@port = port || (config[:https] ? 443 : 80)
end
- @config = DEFAULT_CONFIG.merge(hostname: host).merge(config)
+ @config = DEFAULT_CONFIG.merge(hostname: host).merge!(config)
@started = false
end
diff --git a/lib/plum/client/client_session.rb b/lib/plum/client/client_session.rb
index 0c7e366..f21d2a6 100644
--- a/lib/plum/client/client_session.rb
+++ b/lib/plum/client/client_session.rb
@@ -42,7 +42,7 @@ module Plum
":scheme" => @config[:https] ? "https" : "http",
}.merge(headers)
- response = Response.new(**options, &headers_cb)
+ response = Response.new(self, **options, &headers_cb)
@responses << response
stream = @plum.open_stream
stream.send_headers(headers, end_stream: !body)
diff --git a/lib/plum/client/legacy_client_session.rb b/lib/plum/client/legacy_client_session.rb
index 07ae6a9..3766ad3 100644
--- a/lib/plum/client/legacy_client_session.rb
+++ b/lib/plum/client/legacy_client_session.rb
@@ -39,7 +39,7 @@ module Plum
end
end
- response = Response.new(**options, &headers_cb)
+ response = Response.new(self, **options, &headers_cb)
@requests << [response, headers, body, chunked]
consume_queue
response
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)