aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_req.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-10-29 19:52:27 +0000
committerLoïc Hoguin <[email protected]>2017-10-29 21:03:04 +0000
commitf3d6b05b863fe177a34a8a6ba48c5f263ef8cf82 (patch)
treefc3235ad43880f29186bce373a3c79057c83e060 /src/cowboy_req.erl
parentf4331f7c169309c9017b9628fe3757fc5312270b (diff)
downloadcowboy-f3d6b05b863fe177a34a8a6ba48c5f263ef8cf82.tar.gz
cowboy-f3d6b05b863fe177a34a8a6ba48c5f263ef8cf82.tar.bz2
cowboy-f3d6b05b863fe177a34a8a6ba48c5f263ef8cf82.zip
Add cowboy_req:inform/2,3
User code can now send as many 1xx responses as necessary.
Diffstat (limited to 'src/cowboy_req.erl')
-rw-r--r--src/cowboy_req.erl16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index 1615c07..253564d 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -71,6 +71,8 @@
-export([set_resp_body/2]).
%% @todo set_resp_body/3 with a ContentType or even Headers argument, to set content headers.
-export([has_resp_body/1]).
+-export([inform/2]).
+-export([inform/3]).
-export([reply/2]).
-export([reply/3]).
-export([reply/4]).
@@ -685,6 +687,18 @@ has_resp_body(_) ->
delete_resp_header(Name, Req=#{resp_headers := RespHeaders}) ->
Req#{resp_headers => maps:remove(Name, RespHeaders)}.
+-spec inform(cowboy:http_status(), req()) -> ok.
+inform(Status, Req) ->
+ inform(Status, #{}, Req).
+
+-spec inform(cowboy:http_status(), cowboy:http_headers(), req()) -> ok.
+inform(_, _, #{has_sent_resp := _}) ->
+ error(function_clause); %% @todo Better error message.
+inform(Status, Headers, #{pid := Pid, streamid := StreamID})
+ when is_integer(Status); is_binary(Status) ->
+ Pid ! {{Pid, StreamID}, {inform, Status, Headers}},
+ ok.
+
-spec reply(cowboy:http_status(), Req) -> Req when Req::req().
reply(Status, Req) ->
reply(Status, #{}, Req).
@@ -699,7 +713,7 @@ reply(Status, Headers, Req) ->
-spec reply(cowboy:http_status(), cowboy:http_headers(), resp_body(), Req)
-> Req when Req::req().
reply(_, _, _, #{has_sent_resp := _}) ->
- error(function_clause);
+ error(function_clause); %% @todo Better error message.
reply(Status, Headers, {sendfile, _, 0, _}, Req)
when is_integer(Status); is_binary(Status) ->
do_reply(Status, Headers#{