aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/handlers/resp_h.erl12
-rw-r--r--test/req_SUITE.erl34
2 files changed, 46 insertions, 0 deletions
diff --git a/test/handlers/resp_h.erl b/test/handlers/resp_h.erl
index add90ad..19686ff 100644
--- a/test/handlers/resp_h.erl
+++ b/test/handlers/resp_h.erl
@@ -204,6 +204,18 @@ do(<<"stream_body">>, Req0, Opts) ->
cowboy_req:stream_body(<<0:800000>>, fin, Req0),
{ok, Req0, Opts}
end;
+do(<<"stream_trailers">>, Req0, Opts) ->
+ case cowboy_req:binding(arg, Req0) of
+ _ ->
+ Req = cowboy_req:stream_reply(200, #{
+ <<"trailer">> => <<"grpc-status">>
+ }, Req0),
+ cowboy_req:stream_body(<<"Hello world!">>, nofin, Req),
+ cowboy_req:stream_trailers(#{
+ <<"grpc-status">> => <<"0">>
+ }, Req),
+ {ok, Req, Opts}
+ end;
do(<<"push">>, Req, Opts) ->
case cowboy_req:binding(arg, Req) of
<<"method">> ->
diff --git a/test/req_SUITE.erl b/test/req_SUITE.erl
index 862ee53..4c6e2f8 100644
--- a/test/req_SUITE.erl
+++ b/test/req_SUITE.erl
@@ -841,6 +841,40 @@ stream_body_nofin(Config) ->
%% @todo Crash when calling stream_body after calling reply.
%% @todo Crash when calling stream_body before calling stream_reply.
+stream_trailers(Config) ->
+ doc("Stream body followed by trailer headers."),
+ {200, RespHeaders, <<"Hello world!">>, [
+ {<<"grpc-status">>, <<"0">>}
+ ]} = do_trailers("/resp/stream_trailers", Config),
+ {_, <<"grpc-status">>} = lists:keyfind(<<"trailer">>, 1, RespHeaders),
+ ok.
+
+stream_trailers_no_te(Config) ->
+ doc("Stream body followed by trailer headers."),
+ ConnPid = gun_open(Config),
+ Ref = gun:get(ConnPid, "/resp/stream_trailers", [
+ {<<"accept-encoding">>, <<"gzip">>}
+ ]),
+ {response, nofin, 200, RespHeaders} = gun:await(ConnPid, Ref),
+ {ok, RespBody} = gun:await_body(ConnPid, Ref),
+ gun:close(ConnPid).
+
+do_trailers(Path, Config) ->
+ ConnPid = gun_open(Config),
+ Ref = gun:get(ConnPid, Path, [
+ {<<"accept-encoding">>, <<"gzip">>},
+ {<<"te">>, <<"trailers">>}
+ ]),
+ {response, nofin, Status, RespHeaders} = gun:await(ConnPid, Ref),
+ {ok, RespBody, Trailers} = gun:await_body(ConnPid, Ref),
+ gun:close(ConnPid),
+ {Status, RespHeaders, do_decode(RespHeaders, RespBody), Trailers}.
+
+%% @todo Crash when calling stream_trailers twice.
+%% @todo Crash when calling stream_trailers after the fin flag has been set.
+%% @todo Crash when calling stream_trailers after calling reply.
+%% @todo Crash when calling stream_trailers before calling stream_reply.
+
%% Tests: Push.
%% @todo We want to crash when push is called after reply has been initiated.