Class: HTTP2::Client

Inherits:
Connection show all
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:

Examples:

socket = YourTransport.new

conn = HTTP2::Client.new
conn.on(:frame) {|bytes| socket << bytes }

while bytes = socket.read
  conn << bytes
end

Instance Attribute Summary

Attributes inherited from Connection

#active_stream_count, #error, #state, #stream_limit, #window

Instance Method Summary collapse

Methods inherited from Connection

#goaway, #new_stream, #ping, #receive, #settings

Methods included from Emitter

#add_listener, #emit, #once

Methods included from FlowBuffer

#buffered_amount

Constructor Details

#initialize(*args) ⇒ Client

Initialize new HTTP 2.0 client object.



23
24
25
26
27
28
29
30
# File 'lib/http/2/client.rb', line 23

def initialize(*args)
  @stream_id    = 1
  @state        = :connection_header
  @compressor   = Header::Compressor.new(:request)
  @decompressor = Header::Decompressor.new(:response)

  super
end

Instance Method Details

#send(frame) ⇒ Object

Note:

Client will emit the connection header as the first 24 bytes

Send an outgoing frame. Connection and stream flow control is managed by Connection class.

Parameters:

  • frame (Hash)

See Also:



38
39
40
41
42
43
44
45
46
47
# File 'lib/http/2/client.rb', line 38

def send(frame)
  if @state == :connection_header
    emit(:frame, CONNECTION_HEADER)
    @state = :connected

    settings(stream_limit: @stream_limit, window_limit: @window_limit)
  end

  super(frame)
end