anchor.diff:      {['GET','HEAD','POST'], RD, State}.
   
   malformed_request(RD, State) ->
  +    check_ctype_and_verify_body(RD, State).
  +
  +content_types_provided(RD, State) ->
  +    {[{"application/json", nop}], RD, State}.
  +
  +nop(RD, State) ->
  +    {usage(), RD, State}.
  +
  +process_post(RD, State) ->
  +    case riak_kv_util:mapred_system() of
  +        pipe ->
  +            pipe_mapred(RD, State);
  +        legacy ->
  +            legacy_mapred(RD, State)
  +    end.
  +
  +%% Internal functions
  +send_error(Error, RD)  ->
  +    wrq:set_resp_body(format_error(Error), RD).
  +
  +format_error({error, Message}=Error) when is_atom(Message);
  +                                          is_binary(Message) ->
  +    mochijson2:encode({struct, [Error]});
  +format_error({error, {_,_}=Error}) ->
  +    mochijson2:encode({struct, [Error]});
  +format_error({error, Error}) when is_list(Error) ->
  +    mochijson2:encode({struct, Error});
  +format_error(_Error) ->
  +    mochijson2:encode({struct, [{error, map_reduce_error}]}).
  +
  +check_ctype_and_verify_body(RD, State) ->
  +    handle_ctype_ok(ctype_ok(RD), RD, State).
  +
  +handle_ctype_ok(false, RD, State) ->
  +    {{halt, 415}, RD, State};
  +handle_ctype_ok(true, RD, State) ->
  +    check_body(RD, State).
  +
  +ctype_ok(RD) ->
  +    valid_ctype(wrq:get_req_header("content-type", RD)).
  +
  +valid_ctype(?MAPRED_CTYPE) -> true;
  +valid_ctype(_Ctype) -> false.
  +
  +check_body(RD, State) ->
       {Verified, Message, NewState} =
           case {wrq:method(RD), wrq:req_body(RD)} of
               {'POST', Body} when Body /= undefined ->
  
positive.code:                wrq:set_resp_body(Message, RD))
       end,
       NewState}.
  
  content_types_provided(RD, State) ->
      {[{"application/json", nop}], RD, State}.
  
  nop(RD, State) ->
      {usage(), RD, State}.
  
  process_post(RD, State) ->
      case riak_kv_util:mapred_system() of
          pipe ->
              pipe_mapred(RD, State);
          legacy ->
              legacy_mapred(RD, State)
      end.
  
  %% Internal functions
  send_error(Error, RD)  ->
      wrq:set_resp_body(format_error(Error), RD).
  
  format_error({error, Message}=Error) when is_atom(Message);
                                            is_binary(Message) ->
      mochijson2:encode({struct, [Error]});
  format_error({error, {_,_}=Error}) ->
      mochijson2:encode({struct, [Error]});
  format_error({error, Error}) when is_list(Error) ->
      mochijson2:encode({struct, Error});
  format_error(_Error) ->
      mochijson2:encode({struct, [{error, map_reduce_error}]}).
  
  verify_body(Body, State) ->
      case riak_kv_mapred_json:parse_request(Body) of
  
negative.code: -include_lib("webmachine/include/webmachine.hrl").
  -include_lib("riak_pipe/include/riak_pipe.hrl").
  
  -define(MAPRED_CTYPE, "application/json").
  -define(DEFAULT_TIMEOUT, 60000).
  
  
  