class Client
An HTTP/2 client connection that sends requests and reads responses.
Definitions
def initialize(stream)
Initialize the HTTP/2 client with an IO stream.
Signature
-
parameter
streamIO::Stream The underlying stream.
Implementation
def initialize(stream)
@stream = stream
framer = ::Protocol::HTTP2::Framer.new(@stream)
super(framer)
end
def create_response
Create a new response stream for the next request.
Signature
-
returns
Response The response object to be populated.
Implementation
def create_response
Response::Stream.create(self, self.next_stream_id).response
end
def call(request)
Used by the client to send requests to the remote server.
Implementation
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
def write_request(response, request)
Write a request to the remote server via the given response stream.
Signature
-
parameter
responseResponse The response stream to write through.
-
parameter
requestProtocol::HTTP::Request The request to send.
Implementation
def write_request(response, request)
response.send_request(request)
end
def read_response(response)
Wait for the response headers to arrive.
Signature
-
parameter
responseResponse The response to wait on.
Implementation
def read_response(response)
response.wait
end