class

HTTP2::Connection

Inherits Reference < Object

Constructors

new(io : IO, type : Type)
Source

Instance methods

close(error : Error | Nil = nil, notify : Bool = true)

Terminates the HTTP/2 connection.

This will send a GOAWAY frame if notify is true, reporting an Error::Code optional message if present to report an error, or Error::Code::NO_ERROR to terminate the connection cleanly.

NOTE: doesn't close the IO, only the HTTP/2 connection.

Source
closed?
Source
local_settings

Local settings. You may tune local settings prior to establishing the connection (prior to #write_settings) or later on, in which case you must call #send_settings to report changes to the remote peer.

Source
read_client_preface(truncated = false) : Nil

Reads the expected HTTP2::CLIENT_PREFACE for a server context.

You may set truncated to true if the request line was already read, for example when trying to figure out whether the request was a HTTP/1 or HTTP/2 direct request, where "PRI * HTTP/2.0\r\n" was already consumed.

Source
receive

Call in the main loop to receive individual frames.

Most frames are already being taken care of, so only HEADERS, DATA or PUSH_PROMISE frames should really be interesting. Other frames can be ignored safely.

Unknown frame types are reported with a raw Frame#payload, so a client or server may handle them (e.g. custom extensions). They can be safely ignored.

Source
remote_settings

Settings of remote peer. Updated whenever a SETTINGS frame is received.

Source
send(frame : Frame | Array(Frame)) : Nil

Sends a frame to the connected peer.

One may also send an Array(Frame) for the case when some frames must be sliced (in order to respect max frame size) but must be sent as a single block (multiplexing would cause a protocol error).

So far this only applies to HEADERS (and PUSH_PROMISE) and CONTINUATION frames, otherwise HPACK compression synchronisation could end up corrupted if another HEADERS frame for another stream was sent in between.

Source
send_settings

Sends a SETTINGS frame for the current #local_settings values.

Source
streams
Source
write_client_preface

Writes the HTTP2::CLIENT_PREFACE to initialize an HTTP/2 client connection.

Source
write_settings

Immediately writes local settings to the connection.

This is UNSAFE and MUST only be called for sending the initial SETTINGS frame. Sending changes to #local_settings once the connection established MUST use #send_settings instead!

Source

Nested types