Class: Protocol::HTTP2::Server

Inherits:
Connection show all
Defined in:
lib/protocol/http2/server.rb

Overview

Represents an HTTP/2 server connection. Manages server-side protocol semantics including stream ID allocation, connection preface handling, and settings negotiation.

Instance Attribute Summary

Attributes inherited from Connection

#dependencies, #dependency, #framer, #local_settings, #local_window, #remote_settings, #remote_stream_id, #remote_window, #state, #streams

Instance Method Summary collapse

Methods inherited from Connection

#[], #accept_stream, #client_stream_id?, #close, #close!, #closed?, #closed_stream_id?, #consume_window, #create_push_promise_stream, #create_stream, #decode_headers, #delete, #encode_headers, #id, #idle_stream_id?, #ignore_frame?, #maximum_concurrent_streams, #maximum_frame_size, #next_stream_id, #open!, #process_settings, #read_frame, #receive_continuation, #receive_data, #receive_frame, #receive_goaway, #receive_headers, #receive_ping, #receive_priority_update, #receive_push_promise, #receive_reset_stream, #receive_settings, #receive_window_update, #send_goaway, #send_ping, #send_settings, #server_stream_id?, #synchronize, #update_local_settings, #update_remote_settings, #write_frame, #write_frames

Methods included from FlowControlled

#available_frame_size, #available_size, #consume_local_window, #consume_remote_window, #receive_window_update, #request_window_update, #send_window_update, #update_local_window, #window_updated

Constructor Details

#initialize(framer) ⇒ Server

Initialize a new HTTP/2 server connection.



16
17
18
# File 'lib/protocol/http2/server.rb', line 16

def initialize(framer)
	super(framer, 2)
end

Instance Method Details

#accept_push_promise_stream(stream_id, &block) ⇒ Object

Servers cannot accept push promise streams from clients.

Raises:



67
68
69
# File 'lib/protocol/http2/server.rb', line 67

def accept_push_promise_stream(stream_id, &block)
	raise ProtocolError, "Cannot accept push promises on server!"
end

#enable_push?Boolean

Check if server push is enabled by the client.

Returns:

  • (Boolean)


73
74
75
# File 'lib/protocol/http2/server.rb', line 73

def enable_push?
	@remote_settings.enable_push?
end

#local_stream_id?(id) ⇒ Boolean

Check if the given stream ID represents a locally-initiated stream. Server streams have even numbered IDs.

Returns:

  • (Boolean)


24
25
26
# File 'lib/protocol/http2/server.rb', line 24

def local_stream_id?(id)
	id.even?
end

#read_connection_preface(settings = []) ⇒ Object

Read the HTTP/2 connection preface from the client and send initial settings. This must be called once when the connection is first established.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/protocol/http2/server.rb', line 48

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

#remote_stream_id?(id) ⇒ Boolean

Check if the given stream ID represents a remotely-initiated stream. Client streams have odd numbered IDs.

Returns:

  • (Boolean)


32
33
34
# File 'lib/protocol/http2/server.rb', line 32

def remote_stream_id?(id)
	id.odd?
end

#valid_remote_stream_id?(stream_id) ⇒ Boolean

Check if the given stream ID is valid for remote initiation. Client-initiated streams must have odd numbered IDs.

Returns:

  • (Boolean)


40
41
42
# File 'lib/protocol/http2/server.rb', line 40

def valid_remote_stream_id?(stream_id)
	stream_id.odd?
end