Commits

Anonymous committed 36f1560

cleaner set of final resp body

  • Participants
  • Parent commits 53d1eeb

Comments (0)

Files changed (4)

src/webmachine_decision_core.erl

 	    ErrorHandler = webmachine_dispatcher:get_error_handler(),
 	    Reason = {none, none, []},
 	    ErrorHTML = ErrorHandler:render_error(Code, get(req), Reason),
-            wrcall({append_to_response_body, ErrorHTML});
+            wrcall({set_resp_body, ErrorHTML});
         304 ->
             wrcall({remove_resp_header, "Content-Type"}),
             case resource_call(generate_etag) of
 error_response(Code, Reason) ->
     ErrorHandler = webmachine_dispatcher:get_error_handler(),
     ErrorHTML = ErrorHandler:render_error(Code, get(req), Reason),
-    wrcall({append_to_response_body, ErrorHTML}),
+    wrcall({set_resp_body, ErrorHTML}),
     respond(Code).
 error_response(Reason) ->
     error_response(500, Reason).
         {error, _,_} -> error_response(FinalBody);
         {halt, Code} -> respond(Code);
         nop -> d(v3o18b);
-        _ -> wrcall({append_to_response_body,
+        _ -> wrcall({set_resp_body,
                      encode_body(iolist_to_binary(FinalBody))}),
              d(v3o18b)
     end;

src/webmachine_request.erl

 	 send_response/1,
 	 response_code/0,
 	 set_response_code/1,
+         set_resp_body/1,
 	 response_body/0,
 	 has_response_body/0,
 	 stop/0,
 
 stop() -> gen_server:cast(Pid, stop).
 
+set_resp_body(Body) -> call({set_resp_body, Body}).
 resp_body() -> call(resp_body).
 response_body() -> resp_body().
 

src/webmachine_request_srv.erl

     {reply, Reply, NewState#state{log_data=NewLogData}};
 handle_call(resp_body, _From, State) ->
     {reply, wrq:resp_body(State#state.reqdata), State};
+handle_call({set_resp_body, Body}, _From, State) ->
+    NewState = State#state{reqdata=wrq:set_resp_body(Body,
+                                     State#state.reqdata)},
+    {reply, ok, NewState};
 handle_call(has_resp_body, _From, State) ->
     Reply = case wrq:resp_body(State#state.reqdata) of
                 undefined -> false;
 resp_headers(_RD = #wm_reqdata{resp_headers=RespH}) -> RespH. % mochiheaders
 
 resp_body(_RD = #wm_reqdata{resp_body=undefined}) -> undefined;
-resp_body(_RD = #wm_reqdata{resp_body=RespB}) when is_binary(RespB) -> RespB.
+resp_body(_RD = #wm_reqdata{resp_body=RespB}) when is_binary(RespB) -> RespB;
+resp_body(_RD = #wm_reqdata{resp_body=RespB}) -> iolist_to_binary(RespB).
 
 %% --