Anonymous avatar Anonymous committed 642b31b

nice error if resource tries to use both req_body and stream_req_body

Comments (0)

Files changed (2)


-                bodyfetch=standard, % set to 'stream' if streaming body
+                bodyfetch=undefined,
     {reply, wrq:raw_path(State#state.reqdata), State};
 handle_call(req_headers, _From, State) ->
     {reply, wrq:req_headers(State#state.reqdata), State};
-handle_call(req_body, _From, State=#state{reqdata=RD,bodyfetch=standard}) ->
+handle_call(req_body, _From, State=#state{bodyfetch=stream}) ->
+    {reply, stream_conflict, State};
+handle_call(req_body, _From, State=#state{reqdata=RD}) ->
     {Body, FinalState} = case RD#wm_reqdata.req_body of
         not_fetched_yet ->
             NewState = do_recv_body(State),
             NewRD = NewState#state.reqdata,
-            {NewRD#wm_reqdata.req_body, NewState};
+            {NewRD#wm_reqdata.req_body, NewState#state{bodyfetch=standard}};
         X ->
-            {X, State}
+            {X, State#state{bodyfetch=standard}}
     {reply, Body, FinalState};
-handle_call(req_body, _From, State=#state{bodyfetch=stream}) ->
+handle_call({stream_req_body,_}, _From, State=#state{bodyfetch=standard}) ->
     {reply, stream_conflict, State};
-handle_call({stream_req_body, MaxHunk}, _From, State=#state{reqdata=RD}) ->
+handle_call({stream_req_body, MaxHunk}, _From, State) ->
     {reply, do_stream_body(State, MaxHunk), State#state{bodyfetch=stream}};
 handle_call(resp_headers, _From, State) ->
     {reply, wrq:resp_headers(State#state.reqdata), State};
 req_headers(_RD = #wm_reqdata{req_headers=ReqH}) -> ReqH. % mochiheaders
 req_body(_RD = #wm_reqdata{wmreq=WMReq}) ->
-    case WMReq:req_body() of
-        stream_conflict ->
-            erlang:error("wrq:req_body called after wrq:stream_req_body");
-        Body ->
-            Body
-    end.
+    maybe_conflict_body(WMReq:req_body()).
 stream_req_body(_RD = #wm_reqdata{wmreq=WMReq}, MaxHunk) ->
-    WMReq:stream_req_body(MaxHunk).
+    maybe_conflict_body(WMReq:stream_req_body(MaxHunk)).
+maybe_conflict_body(BodyResponse) ->
+    case BodyResponse of
+        stream_conflict ->
+            erlang:error("wrq:req_body and wrq:stream_req_body conflict");
+        _ ->
+            BodyResponse
+    end.
 resp_redirect(_RD = #wm_reqdata{resp_redirect=true}) -> true;
 resp_redirect(_RD = #wm_reqdata{resp_redirect=false}) -> false.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.