aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-02-11 09:03:13 +0100
committerLoïc Hoguin <[email protected]>2013-02-11 09:03:13 +0100
commit40b8d0befcd8b310a7a48e07df7d629153903cca (patch)
treeedd79574d4a9f6f01fbafe9295814dccd9528e52 /test
parent65ed13d2da2e6bab65fcde7db2e46060c33be71f (diff)
downloadcowboy-40b8d0befcd8b310a7a48e07df7d629153903cca.tar.gz
cowboy-40b8d0befcd8b310a7a48e07df7d629153903cca.tar.bz2
cowboy-40b8d0befcd8b310a7a48e07df7d629153903cca.zip
Better handle socket closing with loop handlers
We now read from the socket to be able to detect errors or TCP close events, and buffer the data if any. Once the data receive goes over a certain limit, which defaults to 5000 bytes, we simply close the connection with an {error, overflow} reason.
Diffstat (limited to 'test')
-rw-r--r--test/http_SUITE.erl16
-rw-r--r--test/http_handler_long_polling.erl2
2 files changed, 18 insertions, 0 deletions
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl
index afe62c3..209be7e 100644
--- a/test/http_SUITE.erl
+++ b/test/http_SUITE.erl
@@ -49,6 +49,7 @@
-export([onresponse_crash/1]).
-export([onresponse_reply/1]).
-export([pipeline/1]).
+-export([pipeline_long_polling/1]).
-export([rest_bad_accept/1]).
-export([rest_created_path/1]).
-export([rest_expires/1]).
@@ -112,6 +113,7 @@ groups() ->
nc_rand,
nc_zero,
pipeline,
+ pipeline_long_polling,
rest_bad_accept,
rest_created_path,
rest_expires,
@@ -432,6 +434,8 @@ The document has moved
<A HREF=\"http://www.google.co.il/\">here</A>.
</BODY></HTML>",
Tests = [
+ {102, <<"GET /long_polling HTTP/1.1\r\nHost: localhost\r\n"
+ "Content-Length: 5000\r\n\r\n", 0:5000/unit:8 >>},
{200, ["GET / HTTP/1.0\r\nHost: localhost\r\n"
"Set-Cookie: ", HugeCookie, "\r\n\r\n"]},
{200, "\r\n\r\n\r\n\r\n\r\nGET / HTTP/1.1\r\nHost: localhost\r\n\r\n"},
@@ -449,6 +453,8 @@ The document has moved
{408, "GET / HTTP/1.1\r\nHost: localhost\r\n\r"},
{414, Huge},
{400, "GET / HTTP/1.1\r\n" ++ Huge},
+ {500, <<"GET /long_polling HTTP/1.1\r\nHost: localhost\r\n"
+ "Content-Length: 100000\r\n\r\n", 0:100000/unit:8 >>},
{505, "GET / HTTP/1.2\r\nHost: localhost\r\n\r\n"},
{closed, ""},
{closed, "\r\n"},
@@ -758,6 +764,16 @@ pipeline(Config) ->
{ok, 200, _, Client11} = cowboy_client:response(Client10),
{error, closed} = cowboy_client:response(Client11).
+pipeline_long_polling(Config) ->
+ Client = ?config(client, Config),
+ {ok, Client2} = cowboy_client:request(<<"GET">>,
+ build_url("/long_polling", Config), Client),
+ {ok, Client3} = cowboy_client:request(<<"GET">>,
+ build_url("/long_polling", Config), Client2),
+ {ok, 102, _, Client4} = cowboy_client:response(Client3),
+ {ok, 102, _, Client5} = cowboy_client:response(Client4),
+ {error, closed} = cowboy_client:response(Client5).
+
rest_bad_accept(Config) ->
Client = ?config(client, Config),
{ok, Client2} = cowboy_client:request(<<"GET">>,
diff --git a/test/http_handler_long_polling.erl b/test/http_handler_long_polling.erl
index 763e1fe..e8cf610 100644
--- a/test/http_handler_long_polling.erl
+++ b/test/http_handler_long_polling.erl
@@ -19,4 +19,6 @@ info(timeout, Req, State) ->
{loop, Req, State - 1, hibernate}.
terminate({normal, shutdown}, _, _) ->
+ ok;
+terminate({error, overflow}, _, _) ->
ok.