anchor.diff:     Http = [iolist_to_binary([Head, $\r, $\n]) | Acc],
      encode(Payload, Http, encode_check_payload(S#http{headers=Headers})).
   
  -
  -%% check if payload needs to be transmitted
  +%%
  +%% encode check message payload
  +%% see http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4
  +%%
  +%% 1. Any response message which "MUST NOT" include a message-body 
  +%%    (such as the 1xx, 204, and 304 responses and any response to 
  +%%    a HEAD request) is always terminated by the first empty line 
  +%%    after the header fields... (Not implemented)
  +%%
  +%% 2. If a Transfer-Encoding header field (section 14.41) is present 
  +%%    and has any value other than "identity", then the transfer-length 
  +%%    is defined by use of the "chunked" transfer-coding (section 3.6), 
  +%%    unless the message is terminated by closing the connection.
  +%%
  +%% 3. If a Content-Length header field (section 14.13) is present, 
  +%%    its decimal value in OCTETs represents both the entity-length 
  +%%    and the transfer-length. The Content-Length header field MUST NOT 
  +%%    be sent if these two lengths are different
  +%%
  +%% 4. If the message uses the media type "multipart/byteranges"... 
  +%%    (Not implemented)
  +%%
  +%% 5. By the server closing the connection. 
  +% encode_check_payload(#http{htline={'GET',  _}}=S) ->
  +%    S#http{is=eof};
  +% encode_check_payload(#http{htline={'HEAD', _}}=S) ->
  +%    S#http{is=eof};
  +% encode_check_payload(#http{htline={'DELETE', _}}=S) ->
  +%    S#http{is=eof};
   encode_check_payload(S) ->
  -   encode_check_entity(lists:keyfind('Content-Length', 1, S#http.headers), S).
  -
  -encode_check_entity({'Content-Length', Len}, S) ->
  -   S#http{is=entity, length=Len};
  -encode_check_entity(false, S) ->
  -   encode_check_chunked(lists:keyfind('Transfer-Encoding', 1, S#http.headers), S).
  -
  -encode_check_chunked({'Transfer-Encoding', chunked}, S) ->
  -   S#http{is=chunk_data};
  -encode_check_chunked({'Transfer-Encoding', <<"chunked">>}, S) ->
  -   S#http{is=chunk_data};
  -encode_check_chunked(false, S) ->
  -   S#http{is=eof}.
  +   element(2, alt(S, [
  +      fun is_payload_chunked/1,
  +      fun is_payload_entity/1,
  +      fun is_payload_eof/1
  +   ])).
  +
  +% %% check if payload needs to be transmitted
  +% encode_check_payload(S) ->
  +%    encode_check_entity(lists:keyfind('Content-Length', 1, S#http.headers), S).
  +
  +% encode_check_entity({'Content-Length', Len}, S) ->
  +%    S#http{is=entity, length=Len};
  +% encode_check_entity(false, S) ->
  +%    encode_check_chunked(lists:keyfind('Transfer-Encoding', 1, S#http.headers), S).
  +
  +% encode_check_chunked({'Transfer-Encoding', chunked}, S) ->
  +%    S#http{is=chunk_data};
  +% encode_check_chunked({'Transfer-Encoding', <<"chunked">>}, S) ->
  +%    S#http{is=chunk_data};
  +% encode_check_chunked(false, S) ->
  +%    S#http{is=eof}.
   
   encode_chunk(Chunk, Acc, S) ->
      Size = integer_to_list(size(Chunk), 16),
  
positive.code: encode(Msg,  Acc, #http{is=header}=S) ->
     encode_header(Msg, Acc, S);
  
  %% encode entity payload
  encode(Pckt, Acc, #http{is=entity, length=Len}=S)
   when size(Pckt) < Len ->
     {lists:reverse([Pckt  | Acc]), S#http{length=Len - size(Pckt)}};
  encode(Pckt, Acc, #http{is=entity, length=Len}=S) ->
     %% TODO: preserve Rest to sndbuf
     <<Chunk:Len/binary, _Rest/binary>> = Pckt,
     {lists:reverse([Chunk | Acc]), S#http{is=eof, length=0}};
  
  %% encode chunked payload 
  encode(eof,  Acc, #http{is=chunk_data}=S) ->
  
negative.code:    S#http{is=eof};
  decode_check_payload(S) ->
     element(2, alt(S, [
        fun is_payload_chunked/1,
        fun is_payload_entity/1,
        fun is_payload_eof/1
     ])).
  
  %%
  %% TODO: support q-values
  