Class: Plum::HPACK::Encoder

Inherits:
Object
  • Object
show all
Includes:
Context
Defined in:
lib/plum/hpack/encoder.rb

Instance Attribute Summary

Attributes included from Context

#dynamic_table, #limit, #size

Instance Method Summary collapse

Constructor Details

#initialize(dynamic_table_limit, indexing: true, huffman: true) ⇒ Encoder

Returns a new instance of Encoder.



9
10
11
12
13
# File 'lib/plum/hpack/encoder.rb', line 9

def initialize(dynamic_table_limit, indexing: true, huffman: true)
  super(dynamic_table_limit)
  @indexing = indexing
  @huffman = huffman
end

Instance Method Details

#encode(headers) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/plum/hpack/encoder.rb', line 14

def encode(headers)
  out = "".b
  headers.each do |name, value|
    name = name.to_s
    value = value.to_s
    if index = search(name, value)
      out << encode_indexed(index)
    elsif index = search_half(name)
      out << encode_half_indexed(index, value)
    else
      out << encode_literal(name, value)
    end
  end
  out
end