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, #close_if_drained!, #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.
22 23 24 25 26 27 28 |
# File 'lib/async/http/protocol/http2/client.rb', line 22 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.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/async/http/protocol/http2/client.rb', line 37 def call(request) # The remote peer has sent a GOAWAY frame, so it will not process any new streams on this connection. The request has not been sent yet, so it is safe to retry it on a new connection, even if it is not idempotent. This is checked first, because a connection with no streams left to drain is closed by the GOAWAY itself. raise ::Protocol::HTTP::RefusedError, "Connection is going away!" if self.goaway_received? # The connection can close after being acquired from the pool. No stream has been created yet, so the request has not been written and is safe to retry. raise ::Protocol::HTTP::RefusedError, "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.
32 33 34 |
# File 'lib/async/http/protocol/http2/client.rb', line 32 def create_response Response::Stream.create(self, self.next_stream_id).response end |
#read_response(response) ⇒ Object
Wait for the response headers to arrive.
60 61 62 |
# File 'lib/async/http/protocol/http2/client.rb', line 60 def read_response(response) response.wait end |
#write_request(response, request) ⇒ Object
Write a request to the remote server via the given response stream.
54 55 56 |
# File 'lib/async/http/protocol/http2/client.rb', line 54 def write_request(response, request) response.send_request(request) end |