cowboy_req:reply works by side-effect!
Today I learned (2018-01-30)
Tagged:
Let's say you have the following cowboy handler:
reply_with_things(Things, Req, State) ->
{ok, Req1} = cowboy_req:reply(200,
[{<<"content-type">>, <<"application/json">>}],
jiffy:encode({[{things, Things}]}), Req),
_ = some_action(Things),
{ok, Req1, State}.
and some_action/1
crashes. What gets returned to the client?
In turns out that the client will still get the encoded json response, as
cowboy_req:reply
works by side-effect.
Not that you'd want to have code like the above in your system. It's here just for educational purposes.