diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-05-08 15:30:31 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-05-08 15:30:31 +0900 |
commit | 023d9d1d1018c03896914f67c9d87846c3ce081b (patch) | |
tree | 3897c205cd616e0d86aefee7abfa119d5505a115 /lib/plum/client/legacy_client_session.rb | |
parent | ebac7073a61b2b8d5190f1cef0619f0ce2885daa (diff) | |
parent | 6e20e16cf0210782739f53f7dcb15d1f9ede5162 (diff) | |
download | plum-023d9d1d1018c03896914f67c9d87846c3ce081b.tar.gz |
Merge branch 'topic/client-redesign-api'
* topic/client-redesign-api:
readme: fix the flow chart showing how it connects to the server
readme/example: replace obsolete Client#[http-method]! examples
client: add Response#join method
client: call the block passed to Client#request in Response#set_headers
client: make Response's internal methods private
client: Client#resume always waits all requests
client: remove synchronous HTTP method methods
client: OpenSSL::SSL::SSLContext always responds to hostname=
client: replace 'scheme' option with 'https' option
client: remove http2 (enable or disable HTTP/2) option
Diffstat (limited to 'lib/plum/client/legacy_client_session.rb')
-rw-r--r-- | lib/plum/client/legacy_client_session.rb | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/plum/client/legacy_client_session.rb b/lib/plum/client/legacy_client_session.rb index e9ff20b..a12f582 100644 --- a/lib/plum/client/legacy_client_session.rb +++ b/lib/plum/client/legacy_client_session.rb @@ -12,7 +12,6 @@ module Plum @parser = setup_parser @requests = [] @response = nil - @headers_callback = nil end def succ @@ -27,7 +26,7 @@ module Plum def close @closed = true - @response._fail if @response + @response.send(:fail) if @response end def request(headers, body, options, &headers_cb) @@ -41,8 +40,8 @@ module Plum end end - response = Response.new(**options) - @requests << [response, headers, body, chunked, headers_cb] + response = Response.new(self, **options, &headers_cb) + @requests << [response, headers, body, chunked] consume_queue response end @@ -56,9 +55,8 @@ module Plum def consume_queue return if @response || @requests.empty? - response, headers, body, chunked, cb = @requests.shift + response, headers, body, chunked = @requests.shift @response = response - @headers_callback = cb @socket << construct_request(headers) @@ -96,19 +94,18 @@ module Plum def setup_parser parser = HTTP::Parser.new parser.on_headers_complete = proc { + # FIXME: duplicate header name? resp_headers = parser.headers.map { |key, value| [key.downcase, value] }.to_h - @response._headers({ ":status" => parser.status_code.to_s }.merge(resp_headers)) - @headers_callback.call(@response) if @headers_callback + @response.send(:set_headers, { ":status" => parser.status_code.to_s }.merge(resp_headers)) } parser.on_body = proc { |chunk| - @response._chunk(chunk) + @response.send(:add_chunk, chunk) } parser.on_message_complete = proc { |env| - @response._finish + @response.send(:finish) @response = nil - @headers_callback = nil close unless parser.keep_alive? consume_queue } |