Permalink
Browse files

update for latest extend version of cowboy

  • Loading branch information...
1 parent 33c8a7b commit 055139c481944ceaac3c0f905dd838645463f9ef @puzza007 puzza007 committed Nov 1, 2011
Showing with 27 additions and 20 deletions.
  1. +2 −3 rebar.config
  2. +14 −9 src/bigwig_http_rb_stream.erl
  3. +11 −8 src/bigwig_http_stats_stream.erl
View
@@ -5,7 +5,6 @@
{deps_dir, ["deps"]}.
{deps, [
- {cowboy, ".*", {git, "https://github.com/smarkets/cowboy.git", "master"}},
- {jsx, ".*", {git, "https://github.com/spawnfest/jsx.git", "beamspirit"}}
+ {cowboy, ".*", {git, "https://github.com/extend/cowboy.git", {branch, "master"}}},
+ {jsx, ".*", {git, "https://github.com/spawnfest/jsx.git", {branch, "beamspirit"}}}
]}.
-
@@ -5,7 +5,8 @@
-behaviour(cowboy_http_handler).
-behaviour(cowboy_http_websocket_handler).
-export([init/3, handle/2, terminate/2]).
--export([websocket_init/3, websocket_handle/3, websocket_terminate/3]).
+-export([websocket_init/3, websocket_handle/3, websocket_terminate/3,
+ websocket_info/3]).
init({tcp, http}, _Req, _Opts) ->
{upgrade, protocol, cowboy_http_websocket}.
@@ -23,24 +24,28 @@ websocket_init(_TransportName, Req, _Opts) ->
bigwig_pubsubhub:register_client(self()),
{ok, Req, undefined_state}.
-websocket_handle(Bin, Req, State) when is_binary(Bin) ->
- {reply, Bin, Req, State};
+websocket_info({text, Bin} = Msg, Req, State) when is_binary(Bin) ->
+ {reply, Msg, Req, State};
%% handle sasl reports sent form our custom handler
-websocket_handle({bigwig, {bigwig_error_handler, Report}}, Req, State) ->
- {reply, report(bigwig_report_reader:fmt_report({erlang:localtime(), Report})), Req, State};
+websocket_info({bigwig, {bigwig_error_handler, Report}}, Req, State) ->
+ Text = report(bigwig_report_reader:fmt_report({erlang:localtime(), Report})),
+ {reply, {text, Text}, Req, State};
%% ignore other bigwig internal msgs
-websocket_handle({bigwig, _}, Req, State) ->
+websocket_info({bigwig, _}, Req, State) ->
{ok, Req, State};
-websocket_handle({websocket, Msg}, Req, State) ->
- {reply, << "You said: ", Msg/binary >>, Req, State};
+websocket_info({websocket, Msg}, Req, State) ->
+ {reply, {text, << "You said: ", Msg/binary >>}, Req, State};
-websocket_handle(Msg, Req, State) ->
+websocket_info(Msg, Req, State) ->
io:format("Unknown msg to ~p ~p~n", [?MODULE, Msg]),
{ok, Req, State}.
+websocket_handle(_Msg, Req, State) ->
+ {ok, Req, State}.
+
websocket_terminate(_Reason, _Req, _State) ->
ok.
@@ -4,7 +4,8 @@
-behaviour(cowboy_http_handler).
-behaviour(cowboy_http_websocket_handler).
-export([init/3, handle/2, terminate/2]).
--export([websocket_init/3, websocket_handle/3, websocket_terminate/3]).
+-export([websocket_init/3, websocket_handle/3, websocket_terminate/3,
+ websocket_info/3]).
init({tcp, http}, _Req, _Opts) ->
@@ -22,20 +23,22 @@ websocket_init(_TransportName, Req, _Opts) ->
%% TODO handle stuff like {bigwig, {appmon, ... }} and send that too
-websocket_handle({bigwig, {bigwig_stats_sender, Stats}}, Req, State) ->
+websocket_info({bigwig, {bigwig_stats_sender, Stats}}, Req, State) ->
Reply = jsx:term_to_json([{stats, Stats}]),
- {reply, Reply, Req, State};
+ {reply, {text, Reply}, Req, State};
-websocket_handle({bigwig, {bigwig_appmon, Stats}}, Req, State) ->
+websocket_info({bigwig, {bigwig_appmon, Stats}}, Req, State) ->
Reply = jsx:term_to_json([{appmon, Stats}]),
- {reply, Reply, Req, State};
+ {reply, {text, Reply}, Req, State};
-websocket_handle({bigwig, _}, Req, State) ->
+websocket_info({bigwig, _}, Req, State) ->
{ok, Req, State};
-websocket_handle(Msg, Req, State) ->
- io:format("Unhandled msg to ~p ~p\n", [?MODULE, Msg]),
+websocket_info(Info, Req, State) ->
+ io:format("Unhandled msg to ~p ~p\n", [?MODULE, Info]),
{ok, Req, State}.
websocket_terminate(_Reason, _Req, _State) -> ok.
+websocket_handle(_Msg, Req, State) ->
+ {ok, Req, State}.

0 comments on commit 055139c

Please sign in to comment.