Class: Protocol::HTTP2::HeadersFrame

Inherits:
Frame
  • Object
show all
Includes:
Continued, Padded
Defined in:
lib/protocol/http2/headers_frame.rb

Overview

The HEADERS frame is used to open a stream, and additionally carries a header block fragment. HEADERS frames can be sent on a stream in the “idle”, “reserved (local)”, “open”, or “half-closed (remote)” state.

--------------- |Pad Length? (8)| -————------------------------------------------------ |E| Stream Dependency? (31) | -————------------------------------------------------ | Weight? (8) | -————------------------------------------------------ | Header Block Fragment (*) … --------------------------------------------------------------- | Padding (*) … ---------------------------------------------------------------

Constant Summary collapse

TYPE =
0x1

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 included from Continued

#continuation

Attributes inherited from Frame

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

Instance Method Summary collapse

Methods included from Continued

#continued?, #end_headers?, #initialize, #read, #write

Methods included from Padded

#padded?

Methods inherited from Frame

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

Instance Method Details

#apply(connection) ⇒ Object



66
67
68
# File 'lib/protocol/http2/headers_frame.rb', line 66

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

#end_stream?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/protocol/http2/headers_frame.rb', line 36

def end_stream?
  flag_set?(END_STREAM)
end

#inspectObject



70
71
72
# File 'lib/protocol/http2/headers_frame.rb', line 70

def inspect
  "\#<#{self.class} stream_id=#{@stream_id} flags=#{@flags} #{@length || 0}b>"
end

#pack(priority, data, *arguments, **options) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/protocol/http2/headers_frame.rb', line 51

def pack(priority, data, *arguments, **options)
  buffer = String.new.b
  
  if priority
    buffer << priority.pack
    set_flags(PRIORITY)
  else
    clear_flags(PRIORITY)
  end
  
  buffer << data
  
  super(buffer, *arguments, **options)
end

#priority?Boolean

Returns:

  • (Boolean)


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

def priority?
  flag_set?(PRIORITY)
end

#unpackObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/protocol/http2/headers_frame.rb', line 40

def unpack
  data = super
  
  if priority?
    priority = Priority.unpack(data)
    data = data.byteslice(5, data.bytesize - 5)
  end
  
  return priority, data
end