anchor.diff:  
   to_response(Req, State) ->
       {"OK", Req, State}.
  -
  -parse_logplex_body(Body, Req) when is_binary(Body) ->
  -    erlang:error(not_implemented),
  -    Req.
  
positive.code: 
  -export([init/3
           ,rest_init/2
           ,content_types_accepted/2
           ,from_logplex/2
           ,process_post/2
           ,content_types_provided/2
           ,to_response/2
          ]).
  
  child_spec() ->
      cowboy:child_spec(?MODULE, 100,
  
negative.code: rest_init(Req, _Opts) ->
      {ok, Req, undefined}.
  
  allowed_methods(Req, State) ->
      {['POST'], Req, State}.
  
  known_content_type(Req, State) ->
      case cowboy_http_req:header(<<"Content-Type">>, Req) of
          {<<"application/logplex-1">>, Req2} ->
              {true, Req2, State};
          {_, Req2} ->
              {false, Req2, State}
      end.
  
  malformed_request(Req, State) ->
      case has_chan_token(Req, State) of
          {true, Req2, State2} ->
              {false, Req2, State2};
          {false, Req2, State2} ->
              {true, Req2, State2}
      end.
  
  has_chan_token(Req, State) ->
      case cowboy_http_req:header(<<"Logplex-Channel-Token">>, Req) of
          {undefined, Req2} ->
              {false, Req2, State};
          {Token, Req2} when is_binary(Token) ->
              {true, Req2, State#state{token=Token}}
      end.
  
  %% XXX - Doesn't get used in current cowboy rest code. #fail
  %% content_types_accepted(Req, State) ->
  %%     {[{{<<"application">>, <<"x-logplex-1">>, []}, from_logplex},
  %%       {{<<"application">>, <<"logplex-1">>, []}, from_logplex}],
  %%      Req, State}.
  %% from_logplex(Req, State) ->
  %%     case parse_logplex_body(Req, State) of
  %%         {parsed, Req2, State2} ->
  %%             {true, Req2, State2};
  %%         {{error, _Reason}, Req2, State2} ->
  %%             {false, Req2, State2}
  %%     end.
  
  process_post(Req, State = #state{token = Token})
               when is_binary(Token) ->
      case parse_logplex_body(Req, State) of
          {parsed, Req2, State2 = #state{msgs = Msgs}} when is_list(Msgs)->
              route_msgs(Token, Msgs),
              {true, Req2, State2#state{msgs = []}};
          {_, Req2, State2} ->
              %% XXX - Log parse failure
              {false, Req2, State2}
      end.
  
  route_msgs(Token, Msgs) ->
      WorkerState = logplex_worker:init_state(),
      [ logplex_worker:route(Token, Msg, WorkerState)
        || Msg <- Msgs ],
      ok.
  
  parse_logplex_body(Req, State) ->
      {Body, Req2} = cowboy_http_req:body(Req),
      case syslog_parser:parse(Body) of
          {ok, Msgs, _} ->
              case logplex_http_req:header(<<"Logplex-Msg-Count">>, Req2) of
                  {false, Req3} ->
                      {parsed, Req3, State#state{msgs=Msgs}};
                  {Val, Req3} ->
                      try
                          Count = list_to_integer(binary_to_list(Val)),
                          Count = length(Msgs),
                          {parsed, Req3, State#state{msgs=Msgs}}
                      catch
                          _:_ ->
                              {{error, msg_count_mismatch}, Req3, State}
                      end
              end;
          {{error, Reason}, _, _} ->
              {{error, Reason}, Req2, State}
      end.
  
  
  content_types_provided(Req, State) ->
      {[{{<<"text">>, <<"plain">>, []}, to_response}],
  