aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_handler_errors.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-01-06 19:19:34 +0100
committerLoïc Hoguin <[email protected]>2012-01-06 19:19:34 +0100
commit5095c27c657a80d7247c14f5a7e760f5d15fc215 (patch)
tree3193c5561f15c1e30afe1d8dcc7ebdcd65b859c3 /test/http_handler_errors.erl
parent5627277aa270aeb926b151a0dda18318add5bc01 (diff)
parent50578254d5d553a7ccbb82ea1c139bb8c3d37197 (diff)
downloadcowboy-5095c27c657a80d7247c14f5a7e760f5d15fc215.tar.gz
cowboy-5095c27c657a80d7247c14f5a7e760f5d15fc215.tar.bz2
cowboy-5095c27c657a80d7247c14f5a7e760f5d15fc215.zip
Merge branch 'issue-114-tests' of https://github.com/klaar/cowboy into gracefully-handle-crashes
Conflicts: test/http_SUITE.erl
Diffstat (limited to 'test/http_handler_errors.erl')
-rw-r--r--test/http_handler_errors.erl40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/http_handler_errors.erl b/test/http_handler_errors.erl
new file mode 100644
index 0000000..1c23207
--- /dev/null
+++ b/test/http_handler_errors.erl
@@ -0,0 +1,40 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(http_handler_errors).
+-behaviour(cowboy_http_handler).
+-export([init/3, handle/2, terminate/2]).
+
+init({_Transport, http}, Req, _Opts) ->
+ {Case, Req1} = cowboy_http_req:qs_val(<<"case">>, Req),
+ case_init(Case, Req1).
+
+case_init(<<"init_before_reply">> = Case, _Req) ->
+ erlang:error(Case);
+
+case_init(<<"init_after_reply">> = Case, Req) ->
+ {ok, _Req1} = cowboy_http_req:reply(200, [], "http_handler_crashes", Req),
+ erlang:error(Case);
+
+case_init(<<"init_reply_handle_error">> = Case, Req) ->
+ {ok, Req1} = cowboy_http_req:reply(200, [], "http_handler_crashes", Req),
+ {ok, Req1, Case};
+
+case_init(<<"handle_before_reply">> = Case, Req) ->
+ {ok, Req, Case};
+
+case_init(<<"handle_after_reply">> = Case, Req) ->
+ {ok, Req, Case}.
+
+
+handle(_Req, <<"init_reply_handle_error">> = Case) ->
+ erlang:error(Case);
+
+handle(_Req, <<"handle_before_reply">> = Case) ->
+ erlang:error(Case);
+
+handle(Req, <<"handle_after_reply">> = Case) ->
+ {ok, _Req1} = cowboy_http_req:reply(200, [], "http_handler_crashes", Req),
+ erlang:error(Case).
+
+terminate(_Req, _State) ->
+ ok.