aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_req.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-08-24 11:20:14 +0200
committerLoïc Hoguin <[email protected]>2013-08-24 20:21:05 +0200
commitbfb6db1eabb945777627a7ced8ab7f1dbc29af67 (patch)
tree6b288eb0ee65580e108fc440eaaf639ec37025a7 /src/cowboy_req.erl
parentac6c460169436a0f022983f3a614ac7ca3e313cd (diff)
downloadcowboy-bfb6db1eabb945777627a7ced8ab7f1dbc29af67.tar.gz
cowboy-bfb6db1eabb945777627a7ced8ab7f1dbc29af67.tar.bz2
cowboy-bfb6db1eabb945777627a7ced8ab7f1dbc29af67.zip
Simpler code for sending errors following crashes
Diffstat (limited to 'src/cowboy_req.erl')
-rw-r--r--src/cowboy_req.erl14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index 66abcf8..32ff7b0 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -101,6 +101,7 @@
-export([chunked_reply/3]).
-export([chunk/2]).
-export([upgrade_reply/3]).
+-export([maybe_reply/2]).
-export([ensure_response/2]).
%% Private setter/getter API.
@@ -1120,6 +1121,19 @@ upgrade_reply(Status, Headers, Req=#http_req{transport=Transport,
], <<>>, Req),
{ok, Req2#http_req{resp_state=done, resp_headers=[], resp_body= <<>>}}.
+%% @doc Send a reply if one hasn't been sent already.
+%%
+%% Meant to be used internally for sending errors after crashes.
+%% @private
+-spec maybe_reply(cowboy:http_status(), req()) -> ok.
+maybe_reply(Status, Req) ->
+ receive
+ {cowboy_req, resp_sent} -> ok
+ after 0 ->
+ _ = cowboy_req:reply(Status, Req),
+ ok
+ end.
+
%% @doc Ensure the response has been sent fully.
%% @private
-spec ensure_response(req(), cowboy:http_status()) -> ok.