class Server
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
framer
Framer
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
id
Integer
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
id
Integer
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_id
Integer
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
settings
Array
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_id
Integer
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