aboutsummaryrefslogtreecommitdiffstats
path: root/test/handlers
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-07-02 17:28:44 +0200
committerLoïc Hoguin <[email protected]>2019-07-02 17:29:40 +0200
commit4a6503186bf3a72880e7c99be76406550aeded96 (patch)
tree3be68b90bc7813fc87a0ac6167793842fa4557d5 /test/handlers
parent1c03ef37c3b9060db8483e3870771d900e176c97 (diff)
downloadgun-4a6503186bf3a72880e7c99be76406550aeded96.tar.gz
gun-4a6503186bf3a72880e7c99be76406550aeded96.tar.bz2
gun-4a6503186bf3a72880e7c99be76406550aeded96.zip
Add response_inform/response_headers/response_end events
This covers many scenarios but more need to be added.
Diffstat (limited to 'test/handlers')
-rw-r--r--test/handlers/empty_h.erl11
-rw-r--r--test/handlers/hello_h.erl10
-rw-r--r--test/handlers/inform_h.erl16
-rw-r--r--test/handlers/stream_h.erl14
-rw-r--r--test/handlers/trailers_h.erl18
5 files changed, 69 insertions, 0 deletions
diff --git a/test/handlers/empty_h.erl b/test/handlers/empty_h.erl
new file mode 100644
index 0000000..7b634cb
--- /dev/null
+++ b/test/handlers/empty_h.erl
@@ -0,0 +1,11 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(empty_h).
+
+-export([init/2]).
+
+init(Req, State) ->
+ {ok, cowboy_req:reply(200, #{
+ <<"content-type">> => <<"text/plain">>
+ }, Req), State}.
+
diff --git a/test/handlers/hello_h.erl b/test/handlers/hello_h.erl
new file mode 100644
index 0000000..e3c71ab
--- /dev/null
+++ b/test/handlers/hello_h.erl
@@ -0,0 +1,10 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(hello_h).
+
+-export([init/2]).
+
+init(Req, State) ->
+ {ok, cowboy_req:reply(200, #{
+ <<"content-type">> => <<"text/plain">>
+ }, <<"Hello world!">>, Req), State}.
diff --git a/test/handlers/inform_h.erl b/test/handlers/inform_h.erl
new file mode 100644
index 0000000..f62b31f
--- /dev/null
+++ b/test/handlers/inform_h.erl
@@ -0,0 +1,16 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(inform_h).
+
+-export([init/2]).
+
+init(Req, State) ->
+ cowboy_req:inform(103, #{
+ <<"content-type">> => <<"text/plain">>
+ }, Req),
+ cowboy_req:inform(103, #{
+ <<"content-type">> => <<"text/plain">>
+ }, Req),
+ {ok, cowboy_req:reply(200, #{
+ <<"content-type">> => <<"text/plain">>
+ }, <<"Hello world!">>, Req), State}.
diff --git a/test/handlers/stream_h.erl b/test/handlers/stream_h.erl
new file mode 100644
index 0000000..fd6774e
--- /dev/null
+++ b/test/handlers/stream_h.erl
@@ -0,0 +1,14 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(stream_h).
+
+-export([init/2]).
+
+init(Req0, State) ->
+ Req = cowboy_req:stream_reply(200, #{
+ <<"content-type">> => <<"text/plain">>
+ }, Req0),
+ cowboy_req:stream_body(<<"Hello ">>, nofin, Req),
+ cowboy_req:stream_body(<<"world!">>, nofin, Req),
+ %% The stream will be closed by Cowboy.
+ {ok, Req, State}.
diff --git a/test/handlers/trailers_h.erl b/test/handlers/trailers_h.erl
new file mode 100644
index 0000000..a94d974
--- /dev/null
+++ b/test/handlers/trailers_h.erl
@@ -0,0 +1,18 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(trailers_h).
+
+-export([init/2]).
+
+init(Req0, State) ->
+ Req = cowboy_req:stream_reply(200, #{
+ <<"content-type">> => <<"text/plain">>,
+ <<"trailer">> => <<"expires">>
+ }, Req0),
+ cowboy_req:stream_body(<<"Hello ">>, nofin, Req),
+ cowboy_req:stream_body(<<"world!">>, nofin, Req),
+ cowboy_req:stream_trailers(#{
+ <<"expires">> => <<"Sun, 10 Dec 2017 19:13:47 GMT">>
+ }, Req),
+ {ok, Req, State}.
+