mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Add cowboy_req:inform/2,3
User code can now send as many 1xx responses as necessary.
This commit is contained in:
parent
f4331f7c16
commit
f3d6b05b86
11 changed files with 206 additions and 1 deletions
|
@ -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#{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue