anchor.diff:     S#http{is=eof};
   decode_check_payload(S) ->
      element(2, alt(S, [
  -      fun decode_payload_chunked/1,
  -      fun decode_payload_entity/1,
  -      fun decode_payload_eof/1
  +      fun is_payload_chunked/1,
  +      fun is_payload_entity/1,
  +      fun is_payload_eof/1
      ])).
  -
  -decode_payload_chunked(S) ->
  -   case lists:keyfind('Transfer-Encoding', 1, S#http.headers) of
  -      {'Transfer-Encoding', <<"identity">>} ->
  -         false;
  -      {'Transfer-Encoding', <<"chunked">>}  ->
  -         case lists:keyfind('Connection', 1, S#http.headers) of
  -            {'Connection', <<"close">>} ->
  -               false;
  -            _ ->
  -               {ok, S#http{is=eoh, length=chunked}}
  -         end;
  -      _ ->
  -         false
  -   end.
  -
  -decode_payload_entity(S) ->
  -   case lists:keyfind('Transfer-Length', 1, S#http.headers) of
  -      {'Transfer-Length', Len} ->
  -         {ok, S#http{is=eoh, length=Len}};
  -      _ ->
  -         case lists:keyfind('Content-Length', 1, S#http.headers) of
  -            {'Content-Length', Len} ->
  -               {ok, S#http{is=eoh, length=Len}};
  -            _ ->
  -               false
  -         end
  -   end. 
  -
  -decode_payload_eof(S) ->
  -   case lists:keyfind('Connection', 1, S#http.headers) of
  -      {'Connection', <<"close">>} ->
  -         {ok, S#http{is=eoh, length=inf}};
  -      _ ->
  -         false
  -   end.
   
   %%
   %% TODO: support q-values
  
positive.code: alt(Y, [], _) ->
     Y.
  
  
  
  
negative.code: encode(Msg,  Acc, #http{is=header}=S) ->
     encode_header(Msg, Acc, S);
  
  %% decode entity payload (end-of-header / entity first byte)
  encode(Msg, Acc, #http{is=eoh, length=chunked}=S) ->
     encode(Msg, Acc, S#http{is=chunk_data, length=0});
  encode(Msg, Acc, #http{is=eoh}=S) ->
     encode(Msg, Acc, S#http{is=entity});
  
  
  %% 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 
  encode(eof,  Acc, #http{is=chunk_data}=S) ->
  