summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-02-14 17:24:38 +0100
committerLoïc Hoguin <[email protected]>2013-02-14 17:24:38 +0100
commitb813607d036251dcdb977500b6a75c1a110825c4 (patch)
tree96dcfe8deb9215f6585c9755bcfc180c848387e4
parentd9f06ebc5625ac63203122e086b484a422da08fd (diff)
downloadbullet-b813607d036251dcdb977500b6a75c1a110825c4.tar.gz
bullet-b813607d036251dcdb977500b6a75c1a110825c4.tar.bz2
bullet-b813607d036251dcdb977500b6a75c1a110825c4.zip
Update to Cowboy 0.8.0
-rw-r--r--examples/clock/src/clock.erl2
-rw-r--r--examples/clock/src/clock_app.erl15
-rw-r--r--examples/clock/src/toppage_handler.erl6
-rw-r--r--rebar.config2
-rw-r--r--src/bullet_handler.erl44
5 files changed, 37 insertions, 32 deletions
diff --git a/examples/clock/src/clock.erl b/examples/clock/src/clock.erl
index a4a2988..e8547e1 100644
--- a/examples/clock/src/clock.erl
+++ b/examples/clock/src/clock.erl
@@ -20,5 +20,7 @@
%% API.
start() ->
+ ok = application:start(crypto),
+ ok = application:start(ranch),
ok = application:start(cowboy),
ok = application:start(clock).
diff --git a/examples/clock/src/clock_app.erl b/examples/clock/src/clock_app.erl
index 71de61f..9b3985f 100644
--- a/examples/clock/src/clock_app.erl
+++ b/examples/clock/src/clock_app.erl
@@ -11,21 +11,20 @@
%% API.
start(_Type, _Args) ->
- Dispatch = [
+ Dispatch = cowboy_router:compile([
{'_', [
- {[], toppage_handler, []},
- {[<<"bullet">>], bullet_handler, [{handler, stream_handler}]},
- {[<<"static">>, '...'], cowboy_http_static, [
+ {"/", toppage_handler, []},
+ {"/bullet", bullet_handler, [{handler, stream_handler}]},
+ {"/static/[...]", cowboy_static, [
{directory, {priv_dir, bullet, []}},
{mimetypes, [
{<<".js">>, [<<"application/javascript">>]}
]}
]}
]}
- ],
- {ok, _} = cowboy:start_listener(http, 100,
- cowboy_tcp_transport, [{port, 8080}],
- cowboy_http_protocol, [{dispatch, Dispatch}]
+ ]),
+ {ok, _} = cowboy:start_http(http, 100,
+ [{port, 8080}], [{env, [{dispatch, Dispatch}]}]
),
clock_sup:start_link().
diff --git a/examples/clock/src/toppage_handler.erl b/examples/clock/src/toppage_handler.erl
index 66c8400..ee482a6 100644
--- a/examples/clock/src/toppage_handler.erl
+++ b/examples/clock/src/toppage_handler.erl
@@ -5,7 +5,7 @@
-export([init/3]).
-export([handle/2]).
--export([terminate/2]).
+-export([terminate/3]).
init(_Transport, Req, []) ->
{ok, Req, undefined}.
@@ -52,9 +52,9 @@ $(document).ready(function(){
</body>
</html>
">>,
- {ok, Req2} = cowboy_http_req:reply(200, [{'Content-Type', <<"text/html">>}],
+ {ok, Req2} = cowboy_req:reply(200, [{<<"content-type">>, <<"text/html">>}],
Body, Req),
{ok, Req2, State}.
-terminate(_Req, _State) ->
+terminate(_Reason, _Req, _State) ->
ok.
diff --git a/rebar.config b/rebar.config
index 6d19803..4c98aa4 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,7 +1,7 @@
{cover_enabled, true}.
{deps, [
{cowboy, ".*",
- {git, "git://github.com/extend/cowboy.git", {tag, "0.6.1"}}}
+ {git, "git://github.com/extend/cowboy.git", {tag, "0.8.0"}}}
]}.
{eunit_opts, [verbose, {report, {eunit_surefire, [{dir, "."}]}}]}.
{erl_opts, [
diff --git a/src/bullet_handler.erl b/src/bullet_handler.erl
index e8fec71..85b64a1 100644
--- a/src/bullet_handler.erl
+++ b/src/bullet_handler.erl
@@ -13,13 +13,17 @@
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-module(bullet_handler).
-
-behaviour(cowboy_http_handler).
--export([init/3, handle/2, info/3, terminate/2]).
+-behaviour(cowboy_websocket_handler).
--behaviour(cowboy_http_websocket_handler).
--export([websocket_init/3, websocket_handle/3,
- websocket_info/3, websocket_terminate/3]).
+-export([init/3]).
+-export([handle/2]).
+-export([info/3]).
+-export([terminate/3]).
+-export([websocket_init/3]).
+-export([websocket_handle/3]).
+-export([websocket_info/3]).
+-export([websocket_terminate/3]).
-record(state, {
handler :: module(),
@@ -31,32 +35,32 @@
%% HTTP.
init(Transport, Req, Opts) ->
- case cowboy_http_req:header('Upgrade', Req) of
+ case cowboy_req:header(<<"upgrade">>, Req) of
{undefined, Req2} ->
- {Method, Req3} = cowboy_http_req:method(Req2),
+ {Method, Req3} = cowboy_req:method(Req2),
init(Transport, Req3, Opts, Method);
{Bin, Req2} when is_binary(Bin) ->
case cowboy_bstr:to_lower(Bin) of
<<"websocket">> ->
- {upgrade, protocol, cowboy_http_websocket};
+ {upgrade, protocol, cowboy_websocket};
_Any ->
- {ok, Req3} = cowboy_http_req:reply(501, [], [], Req2),
+ {ok, Req3} = cowboy_req:reply(501, [], [], Req2),
{shutdown, Req3, undefined}
end
end.
-init(Transport, Req, Opts, 'GET') ->
+init(Transport, Req, Opts, <<"GET">>) ->
{handler, Handler} = lists:keyfind(handler, 1, Opts),
State = #state{handler=Handler},
case Handler:init(Transport, Req, Opts, once) of
{ok, Req2, HandlerState} ->
- Req3 = cowboy_http_req:compact(Req2),
+ Req3 = cowboy_req:compact(Req2),
{loop, Req3, State#state{handler_state=HandlerState},
?TIMEOUT, hibernate};
{shutdown, Req2, HandlerState} ->
{shutdown, Req2, State#state{handler_state=HandlerState}}
end;
-init(Transport, Req, Opts, 'POST') ->
+init(Transport, Req, Opts, <<"POST">>) ->
{handler, Handler} = lists:keyfind(handler, 1, Opts),
State = #state{handler=Handler},
case Handler:init(Transport, Req, Opts, false) of
@@ -66,22 +70,22 @@ init(Transport, Req, Opts, 'POST') ->
{shutdown, Req2, State#state{handler_state=HandlerState}}
end;
init(_Transport, Req, _Opts, _Method) ->
- {ok, Req2} = cowboy_http_req:reply(405, [], [], Req),
+ {ok, Req2} = cowboy_req:reply(405, [], [], Req),
{shutdown, Req2, undefined}.
handle(Req, State) ->
- {Method, Req2} = cowboy_http_req:method(Req),
+ {Method, Req2} = cowboy_req:method(Req),
handle(Req2, State, Method).
handle(Req, State=#state{handler=Handler, handler_state=HandlerState},
'POST') ->
- case cowboy_http_req:body(Req) of
+ case cowboy_req:body(Req) of
{ok, Data, Req2} ->
case Handler:stream(Data, Req2, HandlerState) of
{ok, Req3, HandlerState2} ->
{ok, Req3, State#state{handler_state=HandlerState2}};
{reply, Reply, Req3, HandlerState2} ->
- {ok, Req4} = cowboy_http_req:reply(200, [], Reply, Req3),
+ {ok, Req4} = cowboy_req:reply(200, [], Reply, Req3),
{ok, Req4, State#state{handler_state=HandlerState2}}
end;
{error, _} ->
@@ -95,13 +99,13 @@ info(Message, Req,
{ok, Req2, HandlerState2} ->
{loop, Req2, State#state{handler_state=HandlerState2}, hibernate};
{reply, Data, Req2, HandlerState2} ->
- {ok, Req3} = cowboy_http_req:reply(200, [], Data, Req2),
+ {ok, Req3} = cowboy_req:reply(200, [], Data, Req2),
{ok, Req3, State#state{handler_state=HandlerState2}}
end.
-terminate(_Req, undefined) ->
+terminate(_Reason, _Req, undefined) ->
ok;
-terminate(Req, #state{handler=Handler, handler_state=HandlerState}) ->
+terminate(_Reason, Req, #state{handler=Handler, handler_state=HandlerState}) ->
Handler:terminate(Req, HandlerState).
%% Websocket.
@@ -111,7 +115,7 @@ websocket_init(Transport, Req, Opts) ->
State = #state{handler=Handler},
case Handler:init(Transport, Req, Opts, true) of
{ok, Req2, HandlerState} ->
- Req3 = cowboy_http_req:compact(Req2),
+ Req3 = cowboy_req:compact(Req2),
{ok, Req3, State#state{handler_state=HandlerState},
?TIMEOUT, hibernate};
{shutdown, Req2, _HandlerState} ->