class Server < Connection
- Inherits from
Connection: #id, #[], #maximum_frame_size, #maximum_concurrent_streams, #closed?, #goaway_received?, #close_if_drained!, #delete, #close, #encode_headers, #decode_headers, #next_stream_id, #ignore_frame?, #synchronize, #read_frame, #send_settings, #close!, #send_goaway, #receive_goaway, #write_frame, #write_frames, #update_local_settings, #update_remote_settings, #process_settings, #open!, #receive_settings, #send_ping, #receive_ping, #receive_data, #accept_stream, #create_stream, #create_push_promise_stream, #receive_headers, #receive_push_promise, #receive_priority_update, #client_stream_id?, #server_stream_id?, #idle_stream_id?, #closed_stream_id?, #receive_reset_stream, #consume_window, #receive_window_update, #receive_continuation, #receive_frame, #available_size, #available_frame_size, #consume_remote_window, #update_local_window, #consume_local_window, #request_window_update, #send_window_update, #window_updated
Represents an HTTP/2 server connection. Manages server-side protocol semantics including stream ID allocation, connection preface handling, and settings negotiation.
Definitions
def initialize(framer)
Initialize a new HTTP/2 server connection.
Signature
-
parameter
framerFramer The frame handler for reading/writing HTTP/2 frames.
Implementation
def initialize(framer)
super(framer, 2)
end
def local_stream_id?(id)
Check if the given stream ID represents a locally-initiated stream. Server streams have even numbered IDs.
Signature
-
parameter
idInteger The stream ID to check.
-
returns
Boolean True if the stream ID is locally-initiated.
Implementation
def local_stream_id?(id)
id.even?
end
def remote_stream_id?(id)
Check if the given stream ID represents a remotely-initiated stream. Client streams have odd numbered IDs.
Signature
-
parameter
idInteger The stream ID to check.
-
returns
Boolean True if the stream ID is remotely-initiated.
Implementation
def remote_stream_id?(id)
id.odd?
end
def valid_remote_stream_id?(stream_id)
Check if the given stream ID is valid for remote initiation. Client-initiated streams must have odd numbered IDs.
Signature
-
parameter
stream_idInteger The stream ID to validate.
-
returns
Boolean True if the stream ID is valid for remote initiation.
Implementation
def valid_remote_stream_id?(stream_id)
stream_id.odd?
end
def read_connection_preface(settings = [])
Read the HTTP/2 connection preface from the client and send initial settings. This must be called once when the connection is first established.
Signature
-
parameter
settingsArray Optional settings to send during preface exchange.
-
raises
ProtocolError If called when not in the new state or preface is invalid.
Implementation
def read_connection_preface(settings = [])
if @state == :new
@framer.read_connection_preface
send_settings(settings)
read_frame do |frame|
unless frame.is_a? SettingsFrame
raise ProtocolError, "First frame must be #{SettingsFrame}, but got #{frame.class}"
end
end
else
raise ProtocolError, "Cannot read connection preface in state #{@state}"
end
end
def accept_push_promise_stream(stream_id, &block)
Servers cannot accept push promise streams from clients.
Signature
-
parameter
stream_idInteger The stream ID (unused).
-
raises
ProtocolError Always, as servers cannot accept push promises.
Implementation
def accept_push_promise_stream(stream_id, &block)
raise ProtocolError, "Cannot accept push promises on server!"
end
def enable_push?
Check if server push is enabled by the client.
Signature
-
returns
Boolean True if push promises are enabled.
Implementation
def enable_push?
@remote_settings.enable_push?
end