class Settings
HTTP/2 connection settings container and management.
Definitions
def initialize
Initialize settings with default values from HTTP/2 specification.
Implementation
def initialize
# These limits are taken from the RFC:
# https://tools.ietf.org/html/rfc7540#section-6.5.2
@header_table_size = 4096
@enable_push = 1
@maximum_concurrent_streams = 0xFFFFFFFF
@initial_window_size = 0xFFFF # 2**16 - 1
@maximum_frame_size = 0x4000 # 2**14
@maximum_header_list_size = 0xFFFFFFFF
@enable_connect_protocol = 0
@no_rfc7540_priorities = 0
end
attr_accessor :header_table_size
Allows the sender to inform the remote endpoint of the maximum size of the header compression table used to decode header blocks, in octets.
attr :enable_push
This setting can be used to disable server push. An endpoint MUST NOT send a PUSH_PROMISE frame if it receives this parameter set to a value of 0.
def enable_push=(value)
Set the server push enable flag.
Signature
-
parameter
value
Integer
Must be 0 (disabled) or 1 (enabled).
-
raises
ProtocolError
If the value is invalid.
Implementation
def enable_push= value
if value == 0 or value == 1
@enable_push = value
else
raise ProtocolError, "Invalid value for enable_push: #{value}"
end
end
def enable_push?
Check if server push is enabled.
Signature
-
returns
Boolean
True if server push is enabled.
Implementation
def enable_push?
@enable_push == 1
end
attr_accessor :maximum_concurrent_streams
Indicates the maximum number of concurrent streams that the sender will allow.
attr :initial_window_size
Indicates the sender's initial window size (in octets) for stream-level flow control.
def initial_window_size=(value)
Set the initial window size for stream-level flow control.
Signature
-
parameter
value
Integer
The window size in octets.
-
raises
ProtocolError
If the value exceeds the maximum allowed.
Implementation
def initial_window_size= value
if value <= MAXIMUM_ALLOWED_WINDOW_SIZE
@initial_window_size = value
else
raise ProtocolError, "Invalid value for initial_window_size: #{value} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}"
end
end
attr :maximum_frame_size
Indicates the size of the largest frame payload that the sender is willing to receive, in octets.
def maximum_frame_size=(value)
Set the maximum frame size the sender is willing to receive.
Signature
-
parameter
value
Integer
The maximum frame size in octets.
-
raises
ProtocolError
If the value is outside the allowed range.
Implementation
def maximum_frame_size= value
if value > MAXIMUM_ALLOWED_FRAME_SIZE
raise ProtocolError, "Invalid value for maximum_frame_size: #{value} > #{MAXIMUM_ALLOWED_FRAME_SIZE}"
elsif value < MINIMUM_ALLOWED_FRAME_SIZE
raise ProtocolError, "Invalid value for maximum_frame_size: #{value} < #{MINIMUM_ALLOWED_FRAME_SIZE}"
else
@maximum_frame_size = value
end
end
attr_accessor :maximum_header_list_size
This advisory setting informs a peer of the maximum size of header list that the sender is prepared to accept, in octets.
def enable_connect_protocol=(value)
Set the CONNECT protocol enable flag.
Signature
-
parameter
value
Integer
Must be 0 (disabled) or 1 (enabled).
-
raises
ProtocolError
If the value is invalid.
Implementation
def enable_connect_protocol= value
if value == 0 or value == 1
@enable_connect_protocol = value
else
raise ProtocolError, "Invalid value for enable_connect_protocol: #{value}"
end
end
def enable_connect_protocol?
Check if CONNECT protocol is enabled.
Signature
-
returns
Boolean
True if CONNECT protocol is enabled.
Implementation
def enable_connect_protocol?
@enable_connect_protocol == 1
end
def no_rfc7540_priorities=(value)
Set the RFC 7540 priorities disable flag.
Signature
-
parameter
value
Integer
Must be 0 (enabled) or 1 (disabled).
-
raises
ProtocolError
If the value is invalid.
Implementation
def no_rfc7540_priorities= value
if value == 0 or value == 1
@no_rfc7540_priorities = value
else
raise ProtocolError, "Invalid value for no_rfc7540_priorities: #{value}"
end
end
def no_rfc7540_priorities?
Check if RFC 7540 priorities are disabled.
Signature
-
returns
Boolean
True if RFC 7540 priorities are disabled.
Implementation
def no_rfc7540_priorities?
@no_rfc7540_priorities == 1
end
def update(changes)
Update settings with a hash of changes.
Signature
-
parameter
changes
Hash
Hash of setting keys and values to update.
Implementation
def update(changes)
changes.each do |key, value|
if name = ASSIGN[key]
self.send(name, value)
end
end
end