aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_SUITE_data/http_loop_stream_recv.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-03-24 14:20:52 +0100
committerLoïc Hoguin <[email protected]>2014-03-24 14:25:09 +0100
commit704f61c9d170ef6d4fa3eec1b8be0c76893d7104 (patch)
tree24847160c5f597720767266c49e32b0ccfe4336f /test/http_SUITE_data/http_loop_stream_recv.erl
parentd4ce3c638de136484fe21b85ea7c15eff055cee3 (diff)
downloadcowboy-704f61c9d170ef6d4fa3eec1b8be0c76893d7104.tar.gz
cowboy-704f61c9d170ef6d4fa3eec1b8be0c76893d7104.tar.bz2
cowboy-704f61c9d170ef6d4fa3eec1b8be0c76893d7104.zip
Remove cowboy_client; use gun for the HTTP test suite
Diffstat (limited to 'test/http_SUITE_data/http_loop_stream_recv.erl')
-rw-r--r--test/http_SUITE_data/http_loop_stream_recv.erl41
1 files changed, 17 insertions, 24 deletions
diff --git a/test/http_SUITE_data/http_loop_stream_recv.erl b/test/http_SUITE_data/http_loop_stream_recv.erl
index 87113c6..9f7646a 100644
--- a/test/http_SUITE_data/http_loop_stream_recv.erl
+++ b/test/http_SUITE_data/http_loop_stream_recv.erl
@@ -8,34 +8,27 @@
init({_, http}, Req, _) ->
receive after 100 -> ok end,
self() ! stream,
- {loop, Req, 1, 100}.
+ {loop, Req, undefined, 100}.
-info(stream, Req, Id) ->
- case stream_next(Req) of
- {ok, Id, Req2} ->
- info(stream, Req2, Id+1);
+info(stream, Req, undefined) ->
+ stream(Req, 1, <<>>).
+
+stream(Req, ID, Acc) ->
+ case cowboy_req:stream_body(Req) of
+ {ok, Data, Req2} ->
+ parse_id(Req2, ID, << Acc/binary, Data/binary >>);
{done, Req2} ->
{ok, Req3} = cowboy_req:reply(200, Req2),
- {ok, Req3, Id}
+ {ok, Req3, undefined}
+ end.
+
+parse_id(Req, ID, Data) ->
+ case Data of
+ << ID:32, Rest/bits >> ->
+ parse_id(Req, ID + 1, Rest);
+ _ ->
+ stream(Req, ID, Data)
end.
terminate({normal, shutdown}, _, _) ->
ok.
-
-stream_next(Req) ->
- stream_next(<<>>, Req).
-
-stream_next(Buffer, Req) ->
- case cowboy_req:stream_body(Req) of
- {ok, Packet, Req2} ->
- case <<Buffer/binary, Packet/binary>> of
- <<Id:32>> ->
- {ok, Id, Req2};
- Buffer2 when byte_size(Buffer2) < 4 ->
- stream_next(Buffer2, Req2);
- _InvalidBuffer ->
- {error, invalid_chunk}
- end;
- Other ->
- Other
- end.