aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-08-01 10:59:43 +0200
committerLoïc Hoguin <[email protected]>2014-08-01 10:59:43 +0200
commitfca1c5d6ed6f5813ae23f0150e33418bc150040d (patch)
tree78a1e810c5e7cd5e536f24aac8c598ef9f066d13
parent4cb547c32dda59f7da53d0f517a7901a60358c57 (diff)
downloadcowlib-fca1c5d6ed6f5813ae23f0150e33418bc150040d.tar.gz
cowlib-fca1c5d6ed6f5813ae23f0150e33418bc150040d.tar.bz2
cowlib-fca1c5d6ed6f5813ae23f0150e33418bc150040d.zip
Add another chunked transfer-encoding test
-rw-r--r--src/cow_http_te.erl22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/cow_http_te.erl b/src/cow_http_te.erl
index 7bd6880..5ab71f4 100644
--- a/src/cow_http_te.erl
+++ b/src/cow_http_te.erl
@@ -41,9 +41,9 @@ dripfeed(<< C, Rest/bits >>, Acc, State, F) ->
dripfeed(Rest, << Acc/binary, C >>, State, F);
{more, _, State2} ->
dripfeed(Rest, <<>>, State2, F);
- {more, _, _, State2} ->
+ {more, _, Length, State2} when is_integer(Length) ->
dripfeed(Rest, <<>>, State2, F);
- {more, _, _, Acc2, State2} ->
+ {more, _, Acc2, State2} ->
dripfeed(Rest, Acc2, State2, F);
{done, _, <<>>} ->
ok;
@@ -270,6 +270,24 @@ stream_chunked_dripfeed_test() ->
"0\r\n"
"\r\n">>, <<>>, {0, 0}, fun stream_chunked/2).
+do_body_to_chunks(_, <<>>, Acc) ->
+ lists:reverse([<<"0\r\n\r\n">>|Acc]);
+do_body_to_chunks(ChunkSize, Body, Acc) ->
+ BodySize = byte_size(Body),
+ ChunkSize2 = case BodySize < ChunkSize of
+ true -> BodySize;
+ false -> ChunkSize
+ end,
+ << Chunk:ChunkSize2/binary, Rest/binary >> = Body,
+ ChunkSizeBin = list_to_binary(integer_to_list(ChunkSize2, 16)),
+ do_body_to_chunks(ChunkSize, Rest,
+ [<< ChunkSizeBin/binary, "\r\n", Chunk/binary, "\r\n" >>|Acc]).
+
+stream_chunked_dripfeed2_test() ->
+ Body = list_to_binary(io_lib:format("~p", [lists:seq(1, 100)])),
+ Body2 = iolist_to_binary(do_body_to_chunks(50, Body, [])),
+ dripfeed(Body2, <<>>, {0, 0}, fun stream_chunked/2).
+
stream_chunked_error_test_() ->
Tests = [
{<<>>, undefined},