anchor.diff:              {next_state, 'SERVER', State#fsm{send=Send}}
         end
      catch _:Reason ->
  -      io:format("--> ~p ~p~n", [Reason, erlang:get_stacktrace()]),
  +      ?NOTICE("knet [http]: failure ~p ~p", [Reason, erlang:get_stacktrace()]),
         pipe:b(Pipe, erlang:element(1, htstream:encode({Reason, make_head()}))),
         {stop, normal, State}
      end.
  
positive.code:             {next_state, 'SERVER', State#fsm{recv=Http}}
        end
     catch _:Reason ->
        % io:format("--> ~p ~p~n", [Reason, erlang:get_stacktrace()]),
        pipe:a(Pipe, erlang:element(1, htstream:encode({Reason, make_head()}))),
        {stop, normal, State#fsm{recv=htstream:new()}}
     end;
  
negative.code: 
  
  
  % %%
  % %% handle outbound HTTP message
  % http_outbound(Msg, Pipe, S) ->
  %    {Pckt, Http} = htstream:encode(Msg, S#fsm.send),
  %    _ = pipe:b(Pipe, Pckt),
  %    case htstream:state(Http) of
  %       eof -> 
  %          case htstream:http(Http) of
  %             {request,  Req} ->
  %                S#fsm{send=htstream:new(Http), req=q:enq(Req, S#fsm.req)};
  %             {response, {Code, _, _}} ->
  %                {{T, Req}, Q} = q:deq(S#fsm.req),
  %                {_, R = {Method, _, Head}} = htstream:http(Req),
  %                Ua   = opts:val('User-Agent', undefined, Head), 
  %                Url  = request_url(R, S#fsm.schema, S#fsm.url),
  %                Byte = htstream:octets(Req)  + htstream:octets(Http), 
  %                Pack = htstream:packets(Req) + htstream:packets(Http),
  %                ?access_log(#log{prot=http, src=S#fsm.peer, dst=Url, req=Method, rsp=Code, ua=Ua, byte=Byte, pack=Pack, time=tempus:diff(T)}),
  %                S#fsm{send=htstream:new(Http), req=Q}
  %          end;
  %       _   -> 
  %          S#fsm{send=Http}
  %    end.
  
  % %%
  % %% handle inbound stream
  % http_inbound(Pckt, Peer, Pipe, S)
  %  when is_binary(Pckt) ->
  %    {Msg, Http} = htstream:decode(Pckt, S#fsm.recv),
  %    Url   = request_url(Msg, S#fsm.schema, S#fsm.url),
  %    Alive = request_header(Msg, 'Connection', S#fsm.keepalive),
  %    _ = pass_inbound_http(Msg, Peer, Url, Pipe),
  %    case htstream:state(Http) of
  %       eof -> 
  %          % time to meaningful response
  %          _ = knet:trace(S#fsm.trace, {http, ttmr, tempus:diff(S#fsm.ts)}),
  %          _ = pipe:b(Pipe, {http, Url, eof}),
  %          case htstream:http(Http) of
  %             {request,  _} ->
  %                S#fsm{url=Url, keepalive=Alive, recv=htstream:new(Http), req=q:enq({S#fsm.ts, Http}, S#fsm.req)};
  %             {response, _} ->
  %                S#fsm{url=Url, keepalive=Alive, recv=htstream:new(Http)}
  %          end;
  %       eoh -> 
  %          % time to first byte
  %          _ = knet:trace(S#fsm.trace, {http, ttfb, tempus:diff(S#fsm.ts)}),
  %          http_inbound(<<>>, Peer, Pipe, S#fsm{url=Url, keepalive=Alive, recv=Http, ts=os:timestamp()});
  %       _   -> 
  %          S#fsm{url=Url, keepalive=Alive, recv=Http}
  %    end.
  
  % %%
  % %% handle http failure
  % http_failure(Reason, Pipe, Side, S) ->
  %    %%io:format("----> ~p ~p~n", [Reason, erlang:get_stacktrace()]),
  %    {Msg, _} = htstream:encode({Reason, [{'Server', ?HTTP_SERVER}]}),
  %    _ = pipe:Side(Pipe, Msg),
  %    S#fsm{recv = htstream:new()}.
  
  
  
  
  % %%
  % %% decode request header
  % request_header({Mthd, Url, Heads}, Header, Default)
  %  when is_atom(Mthd), is_binary(Url) ->
  %    case lists:keyfind(Header, 1, Heads) of
  %       false    -> Default;
  %       {_, Val} -> Val
  %    end;
  % request_header(_, _, Default) ->
  %    Default.
  
  
  % %%
  % %% pass inbound http traffic to chain
  % pass_inbound_http({Method, _Path, Heads}, {IP, _}, Url, Pipe) ->
  %    ?DEBUG("knet http ~p: request ~p ~p", [self(), Method, Url]),
  %    %% TODO: Handle Cookie and Request (similar to PHP $_REQUEST)
  %    Env = [{peer, IP}],
  %    _   = pipe:b(Pipe, {http, Url, {Method, Heads, Env}}); 
  % pass_inbound_http([], _Peer, _Url, _Pipe) ->
  %    ok;
  % pass_inbound_http(Chunk, _Peer, Url, Pipe) 
  %  when is_list(Chunk) ->
  %    _ = pipe:b(Pipe, {http, Url, iolist_to_binary(Chunk)}).
  
  
  % %%
  