Class: HTTP2::Client
- Inherits:
-
Connection
- Object
- Connection
- HTTP2::Client
- Defined in:
- lib/http/2/client.rb
Overview
HTTP 2.0 client connection class that implements appropriate header compression / decompression algorithms and stream management logic.
Your code is responsible for driving the client object, which in turn performs all of the necessary HTTP 2.0 encoding / decoding, state management, and the rest. A simple example:
Instance Attribute Summary
Attributes inherited from Connection
#active_stream_count, #local_settings, #local_window, #pending_settings, #remote_settings, #remote_window, #state
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(**settings) ⇒ Client
constructor
Initialize new HTTP 2.0 client object.
-
#send(frame) ⇒ Object
Send an outgoing frame.
-
#send_connection_preface ⇒ Object
Emit the connection preface if not yet.
-
#upgrade ⇒ Object
sends the preface and initializes the first stream in half-closed state.
Methods inherited from Connection
#goaway, #new_stream, #ping, #receive, #settings, #window_update
Methods included from Emitter
Methods included from FlowBuffer
Constructor Details
#initialize(**settings) ⇒ Client
Initialize new HTTP 2.0 client object.
21 22 23 24 25 26 27 28 29 |
# File 'lib/http/2/client.rb', line 21 def initialize(**settings) @stream_id = 1 @state = :waiting_connection_preface @local_role = :client @remote_role = :server super end |
Class Method Details
.settings_header(**settings) ⇒ Object
58 59 60 61 |
# File 'lib/http/2/client.rb', line 58 def self.settings_header(**settings) frame = Framer.new.generate(type: :settings, stream: 0, payload: settings) Base64.urlsafe_encode64(frame[9..-1]) end |
Instance Method Details
#send(frame) ⇒ Object
Send an outgoing frame. Connection and stream flow control is managed by Connection class.
36 37 38 39 |
# File 'lib/http/2/client.rb', line 36 def send(frame) send_connection_preface super(frame) end |
#send_connection_preface ⇒ Object
Emit the connection preface if not yet
49 50 51 52 53 54 55 56 |
# File 'lib/http/2/client.rb', line 49 def send_connection_preface return unless @state == :waiting_connection_preface @state = :connected emit(:frame, CONNECTION_PREFACE_MAGIC) payload = @local_settings.select { |k, v| v != SPEC_DEFAULT_CONNECTION_SETTINGS[k] } settings(payload) end |
#upgrade ⇒ Object
sends the preface and initializes the first stream in half-closed state
42 43 44 45 46 |
# File 'lib/http/2/client.rb', line 42 def upgrade fail ProtocolError unless @stream_id == 1 send_connection_preface new_stream(state: :half_closed_local) end |