aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/chunked_hello_world/src/toppage_handler.erl6
-rw-r--r--examples/compress_response/src/toppage_handler.erl6
-rw-r--r--examples/cookie/src/toppage_handler.erl6
-rw-r--r--examples/echo_get/src/toppage_handler.erl6
-rw-r--r--examples/echo_post/src/toppage_handler.erl6
-rw-r--r--examples/eventsource/src/eventsource_handler.erl4
-rw-r--r--examples/hello_world/src/toppage_handler.erl6
-rw-r--r--examples/rest_basic_auth/src/toppage_handler.erl2
-rw-r--r--examples/rest_hello_world/src/toppage_handler.erl2
-rw-r--r--examples/rest_pastebin/src/toppage_handler.erl2
-rw-r--r--examples/rest_stream_response/src/toppage_handler.erl2
-rw-r--r--examples/ssl_hello_world/src/toppage_handler.erl6
-rw-r--r--examples/upload/src/upload_handler.erl6
-rw-r--r--examples/web_server/src/directory_handler.erl2
-rw-r--r--examples/websocket/src/ws_handler.erl2
15 files changed, 16 insertions, 48 deletions
diff --git a/examples/chunked_hello_world/src/toppage_handler.erl b/examples/chunked_hello_world/src/toppage_handler.erl
index 6b47156..cb1d130 100644
--- a/examples/chunked_hello_world/src/toppage_handler.erl
+++ b/examples/chunked_hello_world/src/toppage_handler.erl
@@ -4,16 +4,12 @@
-module(toppage_handler).
-export([init/2]).
--export([handle/2]).
init(Req, Opts) ->
- {http, Req, Opts}.
-
-handle(Req, State) ->
Req2 = cowboy_req:chunked_reply(200, Req),
cowboy_req:chunk("Hello\r\n", Req2),
timer:sleep(1000),
cowboy_req:chunk("World\r\n", Req2),
timer:sleep(1000),
cowboy_req:chunk("Chunked!\r\n", Req2),
- {ok, Req2, State}.
+ {ok, Req2, Opts}.
diff --git a/examples/compress_response/src/toppage_handler.erl b/examples/compress_response/src/toppage_handler.erl
index 09c8689..4631f71 100644
--- a/examples/compress_response/src/toppage_handler.erl
+++ b/examples/compress_response/src/toppage_handler.erl
@@ -4,12 +4,8 @@
-module(toppage_handler).
-export([init/2]).
--export([handle/2]).
init(Req, Opts) ->
- {http, Req, Opts}.
-
-handle(Req, State) ->
BigBody =
<<"A cowboy is an animal herder who tends cattle on ranches in North America,
traditionally on horseback, and often performs a multitude of other ranch-
@@ -24,4 +20,4 @@ considerable respect for their achievements. There are also cattle handlers
in many other parts of the world, particularly South America and Australia,
who perform work similar to the cowboy in their respective nations.\n">>,
Req2 = cowboy_req:reply(200, [], BigBody, Req),
- {ok, Req2, State}.
+ {ok, Req2, Opts}.
diff --git a/examples/cookie/src/toppage_handler.erl b/examples/cookie/src/toppage_handler.erl
index d1a1126..52e155b 100644
--- a/examples/cookie/src/toppage_handler.erl
+++ b/examples/cookie/src/toppage_handler.erl
@@ -4,12 +4,8 @@
-module(toppage_handler).
-export([init/2]).
--export([handle/2]).
init(Req, Opts) ->
- {http, Req, Opts}.
-
-handle(Req, State) ->
NewValue = integer_to_list(random:uniform(1000000)),
Req2 = cowboy_req:set_resp_cookie(
<<"server">>, NewValue, [{path, <<"/">>}], Req),
@@ -22,4 +18,4 @@ handle(Req, State) ->
Req3 = cowboy_req:reply(200,
[{<<"content-type">>, <<"text/html">>}],
Body, Req2),
- {ok, Req3, State}.
+ {ok, Req3, Opts}.
diff --git a/examples/echo_get/src/toppage_handler.erl b/examples/echo_get/src/toppage_handler.erl
index be657c6..a7c8d7f 100644
--- a/examples/echo_get/src/toppage_handler.erl
+++ b/examples/echo_get/src/toppage_handler.erl
@@ -4,16 +4,12 @@
-module(toppage_handler).
-export([init/2]).
--export([handle/2]).
init(Req, Opts) ->
- {http, Req, Opts}.
-
-handle(Req, State) ->
Method = cowboy_req:method(Req),
#{echo := Echo} = cowboy_req:match_qs(Req, [echo]),
Req2 = echo(Method, Echo, Req),
- {ok, Req2, State}.
+ {ok, Req2, Opts}.
echo(<<"GET">>, undefined, Req) ->
cowboy_req:reply(400, [], <<"Missing echo parameter.">>, Req);
diff --git a/examples/echo_post/src/toppage_handler.erl b/examples/echo_post/src/toppage_handler.erl
index 2bafed0..de75e5e 100644
--- a/examples/echo_post/src/toppage_handler.erl
+++ b/examples/echo_post/src/toppage_handler.erl
@@ -4,16 +4,12 @@
-module(toppage_handler).
-export([init/2]).
--export([handle/2]).
init(Req, Opts) ->
- {http, Req, Opts}.
-
-handle(Req, State) ->
Method = cowboy_req:method(Req),
HasBody = cowboy_req:has_body(Req),
Req2 = maybe_echo(Method, HasBody, Req),
- {ok, Req2, State}.
+ {ok, Req2, Opts}.
maybe_echo(<<"POST">>, true, Req) ->
{ok, PostVals, Req2} = cowboy_req:body_qs(Req),
diff --git a/examples/eventsource/src/eventsource_handler.erl b/examples/eventsource/src/eventsource_handler.erl
index 3aa60e7..c896638 100644
--- a/examples/eventsource/src/eventsource_handler.erl
+++ b/examples/eventsource/src/eventsource_handler.erl
@@ -10,12 +10,12 @@ init(Req, Opts) ->
Headers = [{<<"content-type">>, <<"text/event-stream">>}],
Req2 = cowboy_req:chunked_reply(200, Headers, Req),
erlang:send_after(1000, self(), {message, "Tick"}),
- {long_polling, Req2, Opts, 5000}.
+ {cowboy_loop, Req2, Opts, 5000}.
info({message, Msg}, Req, State) ->
cowboy_req:chunk(["id: ", id(), "\ndata: ", Msg, "\n\n"], Req),
erlang:send_after(1000, self(), {message, "Tick"}),
- {loop, Req, State}.
+ {ok, Req, State}.
id() ->
{Mega, Sec, Micro} = erlang:now(),
diff --git a/examples/hello_world/src/toppage_handler.erl b/examples/hello_world/src/toppage_handler.erl
index 18a6343..e8e672e 100644
--- a/examples/hello_world/src/toppage_handler.erl
+++ b/examples/hello_world/src/toppage_handler.erl
@@ -4,13 +4,9 @@
-module(toppage_handler).
-export([init/2]).
--export([handle/2]).
init(Req, Opts) ->
- {http, Req, Opts}.
-
-handle(Req, State) ->
Req2 = cowboy_req:reply(200, [
{<<"content-type">>, <<"text/plain">>}
], <<"Hello world!">>, Req),
- {ok, Req2, State}.
+ {ok, Req2, Opts}.
diff --git a/examples/rest_basic_auth/src/toppage_handler.erl b/examples/rest_basic_auth/src/toppage_handler.erl
index 59c5888..18a8cae 100644
--- a/examples/rest_basic_auth/src/toppage_handler.erl
+++ b/examples/rest_basic_auth/src/toppage_handler.erl
@@ -9,7 +9,7 @@
-export([to_text/2]).
init(Req, Opts) ->
- {rest, Req, Opts}.
+ {cowboy_rest, Req, Opts}.
is_authorized(Req, State) ->
case cowboy_req:parse_header(<<"authorization">>, Req) of
diff --git a/examples/rest_hello_world/src/toppage_handler.erl b/examples/rest_hello_world/src/toppage_handler.erl
index 5b0dfc8..7657281 100644
--- a/examples/rest_hello_world/src/toppage_handler.erl
+++ b/examples/rest_hello_world/src/toppage_handler.erl
@@ -10,7 +10,7 @@
-export([hello_to_text/2]).
init(Req, Opts) ->
- {rest, Req, Opts}.
+ {cowboy_rest, Req, Opts}.
content_types_provided(Req, State) ->
{[
diff --git a/examples/rest_pastebin/src/toppage_handler.erl b/examples/rest_pastebin/src/toppage_handler.erl
index 89fd786..80974fe 100644
--- a/examples/rest_pastebin/src/toppage_handler.erl
+++ b/examples/rest_pastebin/src/toppage_handler.erl
@@ -17,7 +17,7 @@
init(Req, Opts) ->
random:seed(now()),
- {rest, Req, Opts}.
+ {cowboy_rest, Req, Opts}.
allowed_methods(Req, State) ->
{[<<"GET">>, <<"POST">>], Req, State}.
diff --git a/examples/rest_stream_response/src/toppage_handler.erl b/examples/rest_stream_response/src/toppage_handler.erl
index 6c66d21..61f5ab9 100644
--- a/examples/rest_stream_response/src/toppage_handler.erl
+++ b/examples/rest_stream_response/src/toppage_handler.erl
@@ -8,7 +8,7 @@
-export([streaming_csv/2]).
init(Req, Table) ->
- {rest, Req, Table}.
+ {cowboy_rest, Req, Table}.
content_types_provided(Req, State) ->
{[
diff --git a/examples/ssl_hello_world/src/toppage_handler.erl b/examples/ssl_hello_world/src/toppage_handler.erl
index 18a6343..e8e672e 100644
--- a/examples/ssl_hello_world/src/toppage_handler.erl
+++ b/examples/ssl_hello_world/src/toppage_handler.erl
@@ -4,13 +4,9 @@
-module(toppage_handler).
-export([init/2]).
--export([handle/2]).
init(Req, Opts) ->
- {http, Req, Opts}.
-
-handle(Req, State) ->
Req2 = cowboy_req:reply(200, [
{<<"content-type">>, <<"text/plain">>}
], <<"Hello world!">>, Req),
- {ok, Req2, State}.
+ {ok, Req2, Opts}.
diff --git a/examples/upload/src/upload_handler.erl b/examples/upload/src/upload_handler.erl
index 63cda96..dec634d 100644
--- a/examples/upload/src/upload_handler.erl
+++ b/examples/upload/src/upload_handler.erl
@@ -4,16 +4,12 @@
-module(upload_handler).
-export([init/2]).
--export([handle/2]).
init(Req, Opts) ->
- {http, Req, Opts}.
-
-handle(Req, State) ->
{ok, Headers, Req2} = cowboy_req:part(Req),
{ok, Data, Req3} = cowboy_req:part_body(Req2),
{file, <<"inputfile">>, Filename, ContentType, _TE}
= cow_multipart:form_data(Headers),
io:format("Received file ~p of content-type ~p as follow:~n~p~n~n",
[Filename, ContentType, Data]),
- {ok, Req3, State}.
+ {ok, Req3, Opts}.
diff --git a/examples/web_server/src/directory_handler.erl b/examples/web_server/src/directory_handler.erl
index 5863bfa..7af67ba 100644
--- a/examples/web_server/src/directory_handler.erl
+++ b/examples/web_server/src/directory_handler.erl
@@ -14,7 +14,7 @@
-export([list_html/2]).
init(Req, Paths) ->
- {rest, Req, Paths}.
+ {cowboy_rest, Req, Paths}.
allowed_methods(Req, State) ->
{[<<"GET">>], Req, State}.
diff --git a/examples/websocket/src/ws_handler.erl b/examples/websocket/src/ws_handler.erl
index 18f9526..eaa9284 100644
--- a/examples/websocket/src/ws_handler.erl
+++ b/examples/websocket/src/ws_handler.erl
@@ -6,7 +6,7 @@
init(Req, Opts) ->
erlang:start_timer(1000, self(), <<"Hello!">>),
- {ws, Req, Opts}.
+ {cowboy_websocket, Req, Opts}.
websocket_handle({text, Msg}, Req, State) ->
{reply, {text, << "That's what she said! ", Msg/binary >>}, Req, State};