Class: Iodine::Http::Http2::HPACK
- Inherits:
-
Object
- Object
- Iodine::Http::Http2::HPACK
- Defined in:
- lib/iodine/http/hpack.rb
Defined Under Namespace
Classes: IndexTable
Instance Method Summary collapse
- #decode(data) ⇒ Object
- #encode(headers = {}) ⇒ Object
-
#initialize ⇒ HPACK
constructor
A new instance of HPACK.
- #resize(max) ⇒ Object
Constructor Details
#initialize ⇒ HPACK
Returns a new instance of HPACK.
60 61 62 63 |
# File 'lib/iodine/http/hpack.rb', line 60 def initialize @decoding_list = IndexTable.new @encoding_list = IndexTable.new end |
Instance Method Details
#decode(data) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/iodine/http/hpack.rb', line 65 def decode data data = StringIO.new data results = {} while (field = decode_field(data)) name = (field[0].is_a?(String) && field[0][0] == ':') ? field[0][1..-1].to_sym : field[0] results[name] ? (results[name].is_a?(String) ? (results[name] = [results[name], field[1]]) : (results[name] << field[1]) ) : (results[name] = field[1]) if field[1] end results end |
#encode(headers = {}) ⇒ Object
74 75 76 77 78 |
# File 'lib/iodine/http/hpack.rb', line 74 def encode headers = {} buffer = ''.force_encoding(::Encoding::ASCII_8BIT) headers.each {|k, v| buffer << encode_field( (k.is_a?(String) ? k : ":#{k.to_s}".freeze) ,v) if v} buffer.force_encoding(::Encoding::ASCII_8BIT) end |
#resize(max) ⇒ Object
79 80 81 82 |
# File 'lib/iodine/http/hpack.rb', line 79 def resize max @decoding_list.resize max @encoding_list.resize max end |