summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-07-11 15:13:37 +0200
committerLoïc Hoguin <[email protected]>2012-07-11 15:13:37 +0200
commit5dc08a53dee5af669729b69900c08779d0daba1b (patch)
tree246d6abfcdee606c99b53df4842dcced6c827bd2
parent9f59b43078b0320b6592dadd752f91c977a7900f (diff)
downloadbullet-5dc08a53dee5af669729b69900c08779d0daba1b.tar.gz
bullet-5dc08a53dee5af669729b69900c08779d0daba1b.tar.bz2
bullet-5dc08a53dee5af669729b69900c08779d0daba1b.zip
Fix a rare crash while reading the body in HTTP POST
Only occured when the client closed the connection before finishing the upload.
-rw-r--r--src/bullet_handler.erl21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/bullet_handler.erl b/src/bullet_handler.erl
index f348b5b..e8fec71 100644
--- a/src/bullet_handler.erl
+++ b/src/bullet_handler.erl
@@ -73,17 +73,20 @@ handle(Req, State) ->
{Method, Req2} = cowboy_http_req:method(Req),
handle(Req2, State, Method).
-handle(_Req, _State, 'GET') ->
- exit(badarg);
handle(Req, State=#state{handler=Handler, handler_state=HandlerState},
'POST') ->
- {ok, Data, Req2} = cowboy_http_req:body(Req),
- case Handler:stream(Data, Req2, HandlerState) of
- {ok, Req3, HandlerState2} ->
- {ok, Req3, State#state{handler_state=HandlerState2}};
- {reply, Reply, Req3, HandlerState2} ->
- {ok, Req4} = cowboy_http_req:reply(200, [], Reply, Req3),
- {ok, Req4, State#state{handler_state=HandlerState2}}
+ case cowboy_http_req:body(Req) of
+ {ok, Data, Req2} ->
+ case Handler:stream(Data, Req2, HandlerState) of
+ {ok, Req3, HandlerState2} ->
+ {ok, Req3, State#state{handler_state=HandlerState2}};
+ {reply, Reply, Req3, HandlerState2} ->
+ {ok, Req4} = cowboy_http_req:reply(200, [], Reply, Req3),
+ {ok, Req4, State#state{handler_state=HandlerState2}}
+ end;
+ {error, _} ->
+ %% An error occurred, stop there.
+ {ok, Req, State}
end.
info(Message, Req,