Class: Iodine::Http::Http2::HPACK::IndexTable

Inherits:
Object
  • Object
show all
Defined in:
lib/iodine/http/hpack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIndexTable

Returns a new instance of IndexTable.



10
11
12
13
14
# File 'lib/iodine/http/hpack.rb', line 10

def initialize
	@list = []
	@size = 4_096 # initial defaul size by standard
	@actual_size = 0
end

Instance Attribute Details

#max_sizeObject

Returns the value of attribute max_size.



9
10
11
# File 'lib/iodine/http/hpack.rb', line 9

def max_size
  @max_size
end

#sizeObject (readonly)

Returns the value of attribute size.



8
9
10
# File 'lib/iodine/http/hpack.rb', line 8

def size
  @size
end

Instance Method Details

#[](index) ⇒ Object Also known as: get_index



15
16
17
18
19
20
# File 'lib/iodine/http/hpack.rb', line 15

def [] index
	raise "HPACK Error - invalid header index: 0" if index == 0
	return STATIC_LIST[index] if index < STATIC_LENGTH
	raise "HPACK Error - invalid header index: #{index}" if index >= ( @list.count + STATIC_LENGTH )
	@list[index - STATIC_LENGTH]
end

#find(*field) ⇒ Object



31
32
33
34
35
36
# File 'lib/iodine/http/hpack.rb', line 31

def find *field
	index = STATIC_LIST.index(field)
	return index if index
	index = @list.index(field)
	index ? (index + STATIC_LENGTH) : nil
end

#find_name(name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/iodine/http/hpack.rb', line 37

def find_name name
	index = 1
	while STATIC_LIST[index]
		return index if STATIC_LIST[index][0] == name
		index += 1
	end
	index = 0
	while @list[index]
		return index+STATIC_LENGTH if @list[index][0] == name
		index += 1
	end
	nil
end

#get_name(index) ⇒ Object



22
23
24
# File 'lib/iodine/http/hpack.rb', line 22

def get_name index
	get_index(index)[0]
end

#insert(*field) ⇒ Object



25
26
27
28
29
30
# File 'lib/iodine/http/hpack.rb', line 25

def insert *field
	@list.unshift field
	field.each {|f| @actual_size += f.to_s.bytesize}; @actual_size += 32
	resize
	field
end

#resize(value = nil) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/iodine/http/hpack.rb', line 50

def resize value = nil
	@size = value if value && value <= 4_096
	while (@actual_size > @size) && @list.any?
		@list.pop.each {|i| @actual_size -= i.to_s.bytesize}
		@actual_size -= 32
	end
	self
end