Class: Baykit::BayServer::Docker::Http::H2::Command::CmdHeaders

Inherits:
H2Command
  • Object
show all
Includes:
Baykit::BayServer::Docker::Http::H2
Defined in:
lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb

Instance Attribute Summary collapse

Attributes inherited from H2Command

#flags, #stream_id

Instance Method Summary collapse

Constructor Details

#initialize(stream_id, flags = nil) ⇒ CmdHeaders

Returns a new instance of CmdHeaders.



34
35
36
37
38
39
40
41
# File 'lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb', line 34

def initialize(stream_id, flags=nil)
  super(H2Type::HEADERS, stream_id, flags)
  @pad_length = 0
  @excluded = false
  @stream_dependency = 0
  @weight = 0
  @header_blocks = []
end

Instance Attribute Details

#excludedObject

Returns the value of attribute excluded.



29
30
31
# File 'lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb', line 29

def excluded
  @excluded
end

#header_blocksObject (readonly)

Returns the value of attribute header_blocks.



32
33
34
# File 'lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb', line 32

def header_blocks
  @header_blocks
end

#pad_lengthObject (readonly)

Returns the value of attribute pad_length.



28
29
30
# File 'lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb', line 28

def pad_length
  @pad_length
end

#stream_dependencyObject (readonly)

Returns the value of attribute stream_dependency.



30
31
32
# File 'lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb', line 30

def stream_dependency
  @stream_dependency
end

#weightObject (readonly)

Returns the value of attribute weight.



31
32
33
# File 'lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb', line 31

def weight
  @weight
end

Instance Method Details

#add_header_block(blk) ⇒ Object



97
98
99
# File 'lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb', line 97

def add_header_block(blk)
  @header_blocks.append(blk)
end

#handle(cmd_handler) ⇒ Object



74
75
76
# File 'lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb', line 74

def handle(cmd_handler)
  return cmd_handler.handle_headers(self)
end

#pack(pkt) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb', line 59

def pack(pkt)
  acc = pkt.new_h2_data_accessor

  if @flags.padded?
    acc.put_byte(@pad_length)
  end

  if @flags.priority?
    acc.put_int(H2Packet.make_stream_dependency32(@excluded, @stream_dependency))
    acc.put_byte(@weight)
  end
  write_header_block(acc)
  super
end

#read_header_block(acc, len) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb', line 78

def read_header_block(acc, len)
  while acc.pos < len
    blk = HeaderBlock.unpack(acc)
    #if(BayLog.trace_mode?)
    #  BayLog.trace "h2: Read header block: #{blk}"
    #end
    @header_blocks << blk
  end
end

#unpack(pkt) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb', line 43

def unpack(pkt)
  super
  acc = pkt.new_h2_data_accessor

  if pkt.flags.padded?
    @pad_length = acc.get_byte
  end
  if pkt.flags.priority?
    val = acc.get_int
    @excluded = H2Packet.extract_flag(val) == 1
    @stream_dependency = H2Packet.extract_int31(val)
    @weight = acc.get_byte
  end
  read_header_block(acc, pkt.data_len())
end

#write_header_block(acc) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb', line 88

def write_header_block(acc)
  @header_blocks.each do |blk|
    #if(BayLog.trace_mode?)
    #  BayLog.trace "h2: Write header block: #{blk}"
    #end
    HeaderBlock.pack(blk, acc)
  end
end