aboutsummaryrefslogtreecommitdiffstats
path: root/examples/echo_post/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-06-08 23:35:02 +0200
committerLoïc Hoguin <[email protected]>2016-06-08 23:35:02 +0200
commit4ced1d09943a2f1a9e22426904560e93d41bb8bf (patch)
tree55f7969d140667bfd172db992e8a3164688c4e8f /examples/echo_post/src
parent1470f8831988845efa07091e452cd0bede09d7b6 (diff)
downloadcowboy-4ced1d09943a2f1a9e22426904560e93d41bb8bf.tar.gz
cowboy-4ced1d09943a2f1a9e22426904560e93d41bb8bf.tar.bz2
cowboy-4ced1d09943a2f1a9e22426904560e93d41bb8bf.zip
Fix echo_post example
Diffstat (limited to 'examples/echo_post/src')
-rw-r--r--examples/echo_post/src/echo_post_app.erl6
-rw-r--r--examples/echo_post/src/toppage_handler.erl15
2 files changed, 12 insertions, 9 deletions
diff --git a/examples/echo_post/src/echo_post_app.erl b/examples/echo_post/src/echo_post_app.erl
index 7d86c53..9bb7591 100644
--- a/examples/echo_post/src/echo_post_app.erl
+++ b/examples/echo_post/src/echo_post_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_post_sup:start_link().
stop(_State) ->
diff --git a/examples/echo_post/src/toppage_handler.erl b/examples/echo_post/src/toppage_handler.erl
index de75e5e..a84bfe5 100644
--- a/examples/echo_post/src/toppage_handler.erl
+++ b/examples/echo_post/src/toppage_handler.erl
@@ -14,16 +14,19 @@ init(Req, Opts) ->
maybe_echo(<<"POST">>, true, Req) ->
{ok, PostVals, Req2} = cowboy_req:body_qs(Req),
Echo = proplists:get_value(<<"echo">>, PostVals),
- echo(Echo, Req2);
+ echo(Echo, Req2),
+ Req2;
maybe_echo(<<"POST">>, false, Req) ->
- cowboy_req:reply(400, [], <<"Missing body.">>, Req);
+ cowboy_req:reply(400, [], <<"Missing body.">>, Req),
+ Req;
maybe_echo(_, _, Req) ->
%% Method not allowed.
- cowboy_req:reply(405, Req).
+ cowboy_req:reply(405, Req),
+ Req.
echo(undefined, Req) ->
cowboy_req:reply(400, [], <<"Missing echo parameter.">>, Req);
echo(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).