Class: Protocol::HTTP2::SettingsFrame

Inherits:
Frame
  • Object
show all
Includes:
Acknowledgement
Defined in:
lib/protocol/http2/settings_frame.rb

Overview

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”.

------------------------------- | Identifier (16) | -------------------------------——————————-+ | Value (32) | ---------------------------------------------------------------

Constant Summary collapse

TYPE =
0x4
FORMAT =
"nN".freeze

Constants inherited from Frame

Frame::HEADER_FORMAT, Frame::LENGTH_HISHIFT, Frame::LENGTH_LOMASK, Frame::STREAM_ID_MASK, Frame::VALID_LENGTH, Frame::VALID_STREAM_ID

Instance Attribute Summary

Attributes inherited from Frame

#flags, #length, #payload, #stream_id, #type

Instance Method Summary collapse

Methods included from Acknowledgement

#acknowledge, #acknowledgement!, #acknowledgement?

Methods inherited from Frame

#<=>, #clear_flags, #flag_set?, #header, #initialize, #inspect, parse_header, #read, #read_header, #set_flags, #to_ary, #valid_type?, #write, #write_header, #write_payload

Constructor Details

This class inherits a constructor from Protocol::HTTP2::Frame

Instance Method Details

#apply(connection) ⇒ Object

Apply this SETTINGS frame to a connection for processing.



270
271
272
# File 'lib/protocol/http2/settings_frame.rb', line 270

def apply(connection)
  connection.receive_settings(self)
end

#connection?Boolean

Check if this frame applies to the connection level.

Returns:

  • (Boolean)


247
248
249
# File 'lib/protocol/http2/settings_frame.rb', line 247

def connection?
  true
end

#pack(settings = []) ⇒ Object

Pack settings parameters into the frame payload.



264
265
266
# File 'lib/protocol/http2/settings_frame.rb', line 264

def pack(settings = [])
  super(settings.map{|s| s.pack(FORMAT)}.join)
end

#read_payload(stream) ⇒ Object

Read and validate the SETTINGS frame payload.



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/protocol/http2/settings_frame.rb', line 278

def read_payload(stream)
  super
  
  if @stream_id != 0
    raise ProtocolError, "Settings apply to connection only, but stream_id was given"
  end
  
  if acknowledgement? and @length != 0
    raise FrameSizeError, "Settings acknowledgement must not contain payload: #{@payload.inspect}"
  end
  
  if (@length % 6) != 0
    raise FrameSizeError, "Invalid frame length"
  end
end

#unpackObject

Unpack settings parameters from the frame payload.



253
254
255
256
257
258
259
260
# File 'lib/protocol/http2/settings_frame.rb', line 253

def unpack
  if buffer = super
    # TODO String#each_slice, or #each_unpack would be nice.
    buffer.scan(/....../m).map{|s| s.unpack(FORMAT)}
  else
    []
  end
end