aboutsummaryrefslogtreecommitdiffstats
path: root/test/handlers
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-06-02 12:31:00 +0200
committerLoïc Hoguin <[email protected]>2017-06-02 12:31:00 +0200
commit767da623f1f7329cb0b0d86c3c1876ccf098d60a (patch)
tree7a59761479939b84aad858680d258307430d65bb /test/handlers
parentcbf7972f10a5ef96e544df446144bb1a05bcc7cf (diff)
downloadcowboy-767da623f1f7329cb0b0d86c3c1876ccf098d60a.tar.gz
cowboy-767da623f1f7329cb0b0d86c3c1876ccf098d60a.tar.bz2
cowboy-767da623f1f7329cb0b0d86c3c1876ccf098d60a.zip
Fix terminate not being called on connection close in HTTP/1.1
Introduces the new stream_handler_SUITE test suite. More cases will be added later on.
Diffstat (limited to 'test/handlers')
-rw-r--r--test/handlers/stream_handler_h.erl34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/handlers/stream_handler_h.erl b/test/handlers/stream_handler_h.erl
new file mode 100644
index 0000000..bb4a6da
--- /dev/null
+++ b/test/handlers/stream_handler_h.erl
@@ -0,0 +1,34 @@
+%% This module behaves differently depending on a specific header.
+
+-module(stream_handler_h).
+-behavior(cowboy_stream).
+
+-export([init/3]).
+-export([data/4]).
+-export([info/3]).
+-export([terminate/3]).
+-export([early_error/5]).
+
+init(StreamID, Req, Opts) ->
+ %% @todo Vary behavior depending on x-test-case.
+ Pid = list_to_pid(binary_to_list(cowboy_req:header(<<"x-test-pid">>, Req))),
+ Pid ! {Pid, self(), init, StreamID, Req, Opts},
+ {[{headers, 200, #{}}], Pid}.
+
+data(StreamID, IsFin, Data, State=Pid) ->
+ Pid ! {Pid, self(), data, StreamID, IsFin, Data, State},
+ {[], State}.
+
+info(StreamID, Info, State=Pid) ->
+ Pid ! {Pid, self(), info, StreamID, Info, State},
+ {[], State}.
+
+terminate(StreamID, Reason, State=Pid) ->
+ Pid ! {Pid, self(), terminate, StreamID, Reason, State},
+ ok.
+
+%% This clause can only test for early errors that reached the required header.
+early_error(StreamID, Reason, PartialReq, Resp, Opts) ->
+ Pid = list_to_pid(binary_to_list(cowboy_req:header(<<"x-test-pid">>, PartialReq))),
+ Pid ! {Pid, self(), early_error, StreamID, Reason, PartialReq, Resp, Opts},
+ Resp.