anchor.diff:                    minsize=0,
                     contextupdate=false}.
   
  -encode(Headers, Encoder=#hpackencoder{contextupdate=ContextUpdate}) ->
  -    {Buf, Encoder2} =
  -        case ContextUpdate of
  -            true ->
  -                context_update(Encoder);
  -            false ->
  -                {<<>>, Encoder}
  -        end,
  -    {Buf2, Encoder3} =
  -        lists:foldl(fun(Header, {Acc, Enc}) ->
  -                            {Chunk, Enc2} = encode_header(Header, Enc),
  -                            {<<Acc/binary, Chunk/binary>>, Enc2}
  -                    end, {Buf, Encoder2}, Headers),
  -    {ok, {Buf2, Encoder3}}.
  +encode(Headers, Encoder=#hpackencoder{contextupdate=ContextUpdate})
  +  when ContextUpdate =:= true ->
  +    {Buf, Encoder2} = context_update(Encoder),
  +    encode(Headers, Buf, Encoder2);
  +encode(Headers, Encoder) ->
  +    encode(Headers, <<>>, Encoder).
  +
  +encode(Headers, IniBuf, Encoder) ->
  +    {ok,
  +     lists:foldl(fun(Header, {Acc, Enc}) ->
  +                         {Chunk, Enc2} = encode_header(Header, Enc),
  +                         {<<Acc/binary, Chunk/binary>>, Enc2}
  +                 end, {IniBuf, Encoder}, Headers)}.
  +
   
   context_update(Encoder=#hpackencoder{
                             minsize=MinSize,
                             context=#headercontext{maxsize=MaxSize}
  -                         }) ->
  -    Buf = case MinSize < MaxSize of
  -              true ->
  -                  encode_table_size(MinSize);
  -              false ->
  -                  <<>>
  -          end,
  -    Buf2 = encode_table_size(MaxSize),
  -    {<<Buf/binary, Buf2/binary>>, Encoder#hpackencoder{contextupdate=false}}.
  +                         }) when MinSize < MaxSize ->
  +    Buf = encode_table_size(MinSize),
  +    context_update(Buf, Encoder);
  +context_update(Encoder) ->
  +    context_update(<<>>, Encoder).
  +
  +context_update(IniBuf, Encoder=#hpackencoder{
  +                                  context=#headercontext{maxsize=MaxSize}
  +                                 }) ->
  +    Buf = encode_table_size(MaxSize),
  +    {<<IniBuf/binary, Buf/binary>>, Encoder#hpackencoder{contextupdate=false}}.
   
   encode_header({Name, Value}, Encoder=#hpackencoder{context=Context}) ->
       case header:search(Name, Value, Context) of
  
positive.code: encode_index(N) ->
      encode_integer(N, 7, 16#80).
  
  encode_indname(N, Value, DoIndexing) ->
      {Prefix, FirstByte} = case DoIndexing of
                                true ->
                                    {6, 16#40};
                                false ->
                                    {4, 0}
                            end,
      Buf = encode_integer(N, Prefix, FirstByte),
      Buf2 = encode_string(Value),
      <<Buf/binary, Buf2/binary>>.
  
  encode_newname(Name, Value, DoIndexing) ->
      FirstByte = case DoIndexing of
                      true ->
                          16#40;
                      false ->
                          0
                  end,
      Buf = <<FirstByte>>,
      Buf2 = encode_string(Name),
      Buf3 = encode_string(Value),
  
negative.code:             {Buf, Encoder#hpackencoder{context=Context2}}
      end.
  
  try_add_header(Name, Value, Context) ->
      DoIndexing = header:should_index(Name, Value, Context),
      try_add_header(Name, Value, DoIndexing, Context).
  
  try_add_header(Name, Value, true, Context) ->
      {ok, Context2} = header:add(Name, Value, Context),
      {true, Context2};
  try_add_header(_Name, _Value, false, Context) ->
      {false, Context}.
  
  encode_table_size(Size) ->
      encode_integer(Size, 5, 16#20).
  