anchor.diff:     encode_chunk(Pckt, Acc, S);
   
   encode(_Pckt, Acc, #http{is=eof}=S) ->
  -   {lists:reverse(Acc), S}.
  +   encode_result(Acc, S).
  +
  +%% 
  +encode_result(Acc, #http{}=S) ->
  +   {lists:reverse(Acc), 
  +      S#http{
  +         packets = S#http.packets + 1
  +        ,octets  = S#http.octets  + erlang:iolist_size(Acc)
  +      }
  +   }.
   
   %%
   encode_http('OPTIONS', Msg, S) -> encode_http_request(Msg, S);
  
positive.code: %% encode entity payload
  encode(Pckt, Acc, #http{is=entity, length=Len}=S)
   when is_integer(Len), size(Pckt) < Len ->
     {lists:reverse([Pckt  | Acc]), S#http{length=Len - size(Pckt)}};
  
  encode(Pckt, Acc, #http{is=entity, length=Len}=S)
   when is_integer(Len) ->
     %% TODO: preserve Rest to sndbuf
     <<Chunk:Len/binary, _Rest/binary>> = Pckt,
     {lists:reverse([Chunk | Acc]), S#http{is=eof, length=0}};
  
  encode(Pckt, Acc, #http{is=entity, length=inf}=S) ->
     % message length is determined by closed connection
     {lists:reverse([Pckt  | Acc]), S};
  
  
  %% encode chunked payload 
  
negative.code: 
  encode(Msg) ->
     encode(Msg, new()).
  encode(Msg, #http{}=S) ->
     encode(Msg, [], S).
  
  
  
  