Browse files

Add func for streaming without prefixing chunk lengths

  • Loading branch information...
1 parent d6fe25b commit 5aa444bb1257e6fd6667b658cc4aaa8938cee4a0 @reiddraper reiddraper committed Dec 14, 2011
Showing with 10 additions and 1 deletion.
  1. +10 −1 src/webmachine_request.erl
View
11 src/webmachine_request.erl
@@ -284,6 +284,12 @@ send_stream_body(Socket, {Data, Next}, SoFar) ->
Size = send_chunk(Socket, Data),
send_stream_body(Socket, Next(), Size + SoFar).
+send_stream_body_no_chunk(Socket, {Data, done}) ->
+ send(Socket, Data);
+send_stream_body_no_chunk(Socket, {Data, Next}) ->
+ send(Socket, Data),
+ send_stream_body_no_chunk(Socket, Next()).
+
send_writer_body(Socket, {Encoder, Charsetter, BodyFun}) ->
put(bytes_written, 0),
Writer = fun(Data) ->
@@ -331,7 +337,7 @@ send_response(Code, PassedState=#wm_reqstate{reqdata=RD}) ->
Body0 = wrq:resp_body(RD),
{Body,Length} = case Body0 of
{stream, StreamBody} -> {{stream, StreamBody}, chunked};
- {known_length_stream, Size, StreamBody} -> {{stream, StreamBody}, Size};
+ {known_length_stream, Size, StreamBody} -> {{known_length_stream, StreamBody}, Size};
{stream, Size, Fun} -> {{stream, Fun(0, Size-1)}, chunked};
{writer, WriteBody} -> {{writer, WriteBody}, chunked};
_ -> {Body0, iolist_size([Body0])}
@@ -346,6 +352,9 @@ send_response(Code, PassedState=#wm_reqstate{reqdata=RD}) ->
case Body of
{stream, Body2} ->
send_stream_body(PassedState#wm_reqstate.socket, Body2);
+ {known_length_stream, Body2} ->
+ send_stream_body_no_chunk(PassedState#wm_reqstate.socket, Body2),
+ Length;
{writer, Body2} ->
send_writer_body(PassedState#wm_reqstate.socket, Body2);
_ ->

0 comments on commit 5aa444b

Please sign in to comment.