lib/protocol/hpack/compressor.rb in protocol-hpack-1.3.0 vs lib/protocol/hpack/compressor.rb in protocol-hpack-1.4.0

- old
+ new

@@ -46,27 +46,31 @@ shorter_huffman: NAIVE_HUFFMAN, } # Responsible for encoding header key-value pairs using HPACK algorithm. class Compressor - def initialize(buffer, context = Context.new) + def initialize(buffer, context = Context.new, table_size_limit: nil) @buffer = buffer @context = context + + @table_size_limit = table_size_limit end - + + attr :table_size_limit + attr :buffer attr :context attr :offset - + def write_byte(byte) @buffer << byte.chr end def write_bytes(bytes) @buffer << bytes end - + # Encodes provided value via integer representation. # - http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-10#section-5.1 # # If I < 2^N - 1, encode I on N bits # Else @@ -177,10 +181,16 @@ # Encodes provided list of HTTP headers. # # @param headers [Array] +[[name, value], ...]+ # @return [Buffer] - def encode(headers) + def encode(headers, table_size = @table_size_limit) + if table_size and table_size != @context.table_size + command = @context.change_table_size(table_size) + + write_header(command) + end + commands = @context.encode(headers) commands.each do |command| write_header(command) end