aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-06-08 20:18:09 +0200
committerLoïc Hoguin <[email protected]>2016-06-08 20:18:09 +0200
commit98323c2d72ffa0a164d525b39290125a6ab3b070 (patch)
treeb11cdf4eb971f1a76856edfe047d1949feef5e84
parentfd07b389524f54f79175a5ac5d9f9050fb66bc61 (diff)
downloadcowboy-98323c2d72ffa0a164d525b39290125a6ab3b070.tar.gz
cowboy-98323c2d72ffa0a164d525b39290125a6ab3b070.tar.bz2
cowboy-98323c2d72ffa0a164d525b39290125a6ab3b070.zip
Fix echo_get example
-rw-r--r--examples/echo_get/src/echo_get_app.erl6
-rw-r--r--examples/echo_get/src/toppage_handler.erl6
-rw-r--r--test/examples_SUITE.erl36
3 files changed, 35 insertions, 13 deletions
diff --git a/examples/echo_get/src/echo_get_app.erl b/examples/echo_get/src/echo_get_app.erl
index d661e9c..b9e0d31 100644
--- a/examples/echo_get/src/echo_get_app.erl
+++ b/examples/echo_get/src/echo_get_app.erl
@@ -16,9 +16,9 @@ start(_Type, _Args) ->
{"/", toppage_handler, []}
]}
]),
- {ok, _} = cowboy:start_http(http, 100, [{port, 8080}], [
- {env, [{dispatch, Dispatch}]}
- ]),
+ {ok, _} = cowboy:start_clear(http, 100, [{port, 8080}], #{
+ env => #{dispatch => Dispatch}
+ }),
echo_get_sup:start_link().
stop(_State) ->
diff --git a/examples/echo_get/src/toppage_handler.erl b/examples/echo_get/src/toppage_handler.erl
index 800284e..92762e8 100644
--- a/examples/echo_get/src/toppage_handler.erl
+++ b/examples/echo_get/src/toppage_handler.erl
@@ -14,9 +14,9 @@ init(Req, Opts) ->
echo(<<"GET">>, undefined, Req) ->
cowboy_req:reply(400, [], <<"Missing echo parameter.">>, Req);
echo(<<"GET">>, Echo, Req) ->
- cowboy_req:reply(200, [
- {<<"content-type">>, <<"text/plain; charset=utf-8">>}
- ], Echo, Req);
+ cowboy_req:reply(200, #{
+ <<"content-type">> => <<"text/plain; charset=utf-8">>
+ }, Echo, Req);
echo(_, _, Req) ->
%% Method not allowed.
cowboy_req:reply(405, Req).
diff --git a/test/examples_SUITE.erl b/test/examples_SUITE.erl
index aa7e507..a461d79 100644
--- a/test/examples_SUITE.erl
+++ b/test/examples_SUITE.erl
@@ -42,19 +42,22 @@ do_get_paths(Example0) ->
{ok, CWD} = file:get_cwd(),
Dir = CWD ++ "/../../examples/" ++ Example,
Rel = Dir ++ "/_rel/" ++ Example ++ "_example/bin/" ++ Example ++ "_example",
- {Dir, Rel}.
+ Log = Dir ++ "/_rel/" ++ Example ++ "_example/log/erlang.log.1",
+ {Dir, Rel, Log}.
do_compile_and_start(Example) ->
- {Dir, Rel} = do_get_paths(Example),
- ct:comment("~s~n", [os:cmd("cd " ++ Dir ++ " && make distclean && make all")]),
- ct:comment("~s~n", [os:cmd(Rel ++ " stop")]),
- ct:comment("~s~n", [os:cmd(Rel ++ " start")]),
+ {Dir, Rel, _} = do_get_paths(Example),
+ %% TERM=dumb disables relx coloring.
+ ct:log("~s~n", [os:cmd("cd " ++ Dir ++ " && make distclean && TERM=dumb make all")]),
+ ct:log("~s~n", [os:cmd(Rel ++ " stop")]),
+ ct:log("~s~n", [os:cmd(Rel ++ " start")]),
timer:sleep(2000),
ok.
do_stop(Example) ->
- {_, Rel} = do_get_paths(Example),
- ct:comment("~s~n", [os:cmd(Rel ++ " stop")]),
+ {_, Rel, Log} = do_get_paths(Example),
+ ct:log("~s~n", [os:cmd(Rel ++ " stop")]),
+ ct:log("~s~n", [element(2, file:read_file(Log))]),
ok.
%% TCP and SSL Hello World.
@@ -89,3 +92,22 @@ do_hello_world(Transport, Protocol, Config) ->
{response, nofin, 200, _} = gun:await(ConnPid, Ref),
{ok, <<"Hello world!">>} = gun:await_body(ConnPid, Ref),
ok.
+
+%% Echo GET and POST.
+
+echo_get(Config) ->
+ doc("GET parameter echo example."),
+ try
+ do_compile_and_start(echo_get),
+ do_echo_get(tcp, http, Config),
+ do_echo_get(tcp, http2, Config)
+ after
+ do_stop(echo_get)
+ end.
+
+do_echo_get(Transport, Protocol, Config) ->
+ ConnPid = gun_open([{port, 8080}, {type, Transport}, {protocol, Protocol}|Config]),
+ Ref = gun:get(ConnPid, "/?echo=this+is+fun"),
+ {response, nofin, 200, _} = gun:await(ConnPid, Ref),
+ {ok, <<"this is fun">>} = gun:await_body(ConnPid, Ref),
+ ok.