Class: Async::HTTP::Protocol::HTTP2::Client
- Inherits:
-
Protocol::HTTP2::Client
- Object
- Protocol::HTTP2::Client
- Async::HTTP::Protocol::HTTP2::Client
- Includes:
- Connection
- Defined in:
- lib/async/http/protocol/http2/client.rb
Overview
An HTTP/2 client connection that sends requests and reads responses.
Instance Attribute Summary
Attributes included from Connection
Instance Method Summary collapse
-
#call(request) ⇒ Object
Used by the client to send requests to the remote server.
-
#create_response ⇒ Object
Create a new response stream for the next request.
-
#initialize(stream) ⇒ Client
constructor
Initialize the HTTP/2 client with an IO stream.
-
#read_response(response) ⇒ Object
Wait for the response headers to arrive.
-
#write_request(response, request) ⇒ Object
Write a request to the remote server via the given response stream.
Methods included from Connection
#as_json, #close, #concurrency, #http1?, #http2?, #peer, #read_in_background, #reusable?, #start_connection, #synchronize, #to_json, #to_s, #version, #viable?, #write_frame, #write_frames
Constructor Details
#initialize(stream) ⇒ Client
Initialize the HTTP/2 client with an IO stream.
21 22 23 24 25 26 27 |
# File 'lib/async/http/protocol/http2/client.rb', line 21 def initialize(stream) @stream = stream framer = ::Protocol::HTTP2::Framer.new(@stream) super(framer) end |
Instance Method Details
#call(request) ⇒ Object
Used by the client to send requests to the remote server.
36 37 38 39 40 41 42 43 44 |
# File 'lib/async/http/protocol/http2/client.rb', line 36 def call(request) raise ::Protocol::HTTP2::Error, "Connection closed!" if self.closed? response = create_response write_request(response, request) read_response(response) return response end |
#create_response ⇒ Object
Create a new response stream for the next request.
31 32 33 |
# File 'lib/async/http/protocol/http2/client.rb', line 31 def create_response Response::Stream.create(self, self.next_stream_id).response end |
#read_response(response) ⇒ Object
Wait for the response headers to arrive.
55 56 57 |
# File 'lib/async/http/protocol/http2/client.rb', line 55 def read_response(response) response.wait end |
#write_request(response, request) ⇒ Object
Write a request to the remote server via the given response stream.
49 50 51 |
# File 'lib/async/http/protocol/http2/client.rb', line 49 def write_request(response, request) response.send_request(request) end |