lib/protocol/http2/settings_frame.rb in protocol-http2-0.14.2 vs lib/protocol/http2/settings_frame.rb in protocol-http2-0.15.0

- old
+ new

@@ -1,25 +1,10 @@ -# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com> -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# frozen_string_literal: true +# Released under the MIT License. +# Copyright, 2019-2023, by Samuel Williams. + require_relative 'ping_frame' module Protocol module HTTP2 class Settings @@ -29,10 +14,22 @@ INITIAL_WINDOW_SIZE = 0x4 MAXIMUM_FRAME_SIZE = 0x5 MAXIMUM_HEADER_LIST_SIZE = 0x6 ENABLE_CONNECT_PROTOCOL = 0x8 + ASSIGN = [ + nil, + :header_table_size=, + :enable_push=, + :maximum_concurrent_streams=, + :initial_window_size=, + :maximum_frame_size=, + :maximum_header_list_size=, + nil, + :enable_connect_protocol=, + ] + # 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_accessor :header_table_size # 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. attr :enable_push @@ -57,12 +54,11 @@ def initial_window_size= value if value <= MAXIMUM_ALLOWED_WINDOW_SIZE @initial_window_size = value else - # An endpoint MUST treat a change to SETTINGS_INITIAL_WINDOW_SIZE that causes any flow-control window to exceed the maximum size as a connection error of type FLOW_CONTROL_ERROR. - raise FlowControlError, "Invalid value for initial_window_size: #{value} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}" + raise ProtocolError, "Invalid value for initial_window_size: #{value} > #{MAXIMUM_ALLOWED_WINDOW_SIZE}" end end # Indicates the size of the largest frame payload that the sender is willing to receive, in octets. attr :maximum_frame_size @@ -104,22 +100,10 @@ @maximum_frame_size = 0x4000 # 2**14 @maximum_header_list_size = 0xFFFFFFFF @enable_connect_protocol = 0 end - ASSIGN = [ - nil, - :header_table_size=, - :enable_push=, - :maximum_concurrent_streams=, - :initial_window_size=, - :maximum_frame_size=, - :maximum_header_list_size=, - nil, nil, - :enable_connect_protocol=, - ] - def update(changes) changes.each do |key, value| if name = ASSIGN[key] self.send(name, value) end @@ -132,11 +116,11 @@ if @header_table_size != other.header_table_size changes << [HEADER_TABLE_SIZE, @header_table_size] end if @enable_push != other.enable_push - changes << [ENABLE_PUSH, @enable_push ? 1 : 0] + changes << [ENABLE_PUSH, @enable_push] end if @maximum_concurrent_streams != other.maximum_concurrent_streams changes << [MAXIMUM_CONCURRENT_STREAMS, @maximum_concurrent_streams] end @@ -207,9 +191,13 @@ @current.maximum_frame_size end def maximum_header_list_size @current.maximum_header_list_size + end + + def enable_connect_protocol + @current.enable_connect_protocol end end # The SETTINGS frame conveys configuration parameters that affect how endpoints communicate, such as preferences and constraints on peer behavior. The SETTINGS frame is also used to acknowledge the receipt of those parameters. Individually, a SETTINGS parameter can also be referred to as a "setting". #