class HTTP2::Connection

Defined in:

connection.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(io : IO, type : Type) #

[View source]

Instance Method Detail

def 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.


[View source]
def closed? : Bool #

[View source]
def local_settings : 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.


[View source]
def 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.


[View source]
def receive : Frame | Nil #

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.


[View source]
def remote_settings : Settings #

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


[View source]
def 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.


[View source]
def send_settings : Nil #

Sends a SETTINGS frame for the current #local_settings values.


[View source]
def streams : Streams #

[View source]
def write_client_preface : Nil #

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


[View source]
def write_settings : Nil #

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!


[View source]