Permalink
Browse files

Flush remaining data when dynamic content is delivered

So, in a script, we can return values without taking care of remaining data
on the socket. This is very usefull to return result early even if the
request content is chunked.
  • Loading branch information...
1 parent 0e1a7c3 commit d09ed3dc622be8d2b17efcd1cda552ee777fe464 @capflam capflam committed Jan 6, 2012
Showing with 18 additions and 0 deletions.
  1. +18 −0 src/yaws_server.erl
View
@@ -2668,29 +2668,47 @@ deliver_dyn_part(CliSock, % essential params
A2, UT, YawsFun, DeliverCont
);
break ->
+ flush(CliSock, CliDataPos, (Arg#arg.headers)#headers.content_length,
+ (Arg#arg.headers)#headers.transfer_encoding),
finish_up_dyn_file(Arg, CliSock);
{page, Page} ->
+ flush(CliSock, CliDataPos, (Arg#arg.headers)#headers.content_length,
+ (Arg#arg.headers)#headers.transfer_encoding),
{page, Page};
Arg2 = #arg{} ->
+ flush(CliSock, CliDataPos, (Arg#arg.headers)#headers.content_length,
+ (Arg#arg.headers)#headers.transfer_encoding),
DeliverCont(Arg2);
{streamcontent, _, _} ->
+ flush(CliSock, CliDataPos, (Arg#arg.headers)#headers.content_length,
+ (Arg#arg.headers)#headers.transfer_encoding),
Priv = deliver_accumulated(Arg, CliSock, decide, undefined, stream),
stream_loop_send(Priv, CliSock, 30000);
%% For other timeout values (other than 30 second)
{streamcontent_with_timeout, _, _, TimeOut} ->
+ flush(CliSock, CliDataPos, (Arg#arg.headers)#headers.content_length,
+ (Arg#arg.headers)#headers.transfer_encoding),
Priv = deliver_accumulated(Arg, CliSock, decide, undefined, stream),
stream_loop_send(Priv, CliSock, TimeOut);
{streamcontent_with_size, Sz, _, _} ->
+ flush(CliSock, CliDataPos, (Arg#arg.headers)#headers.content_length,
+ (Arg#arg.headers)#headers.transfer_encoding),
Priv = deliver_accumulated(Arg, CliSock, decide, Sz, stream),
stream_loop_send(Priv, CliSock, 30000);
{streamcontent_from_pid, _, Pid} ->
+ flush(CliSock, CliDataPos, (Arg#arg.headers)#headers.content_length,
+ (Arg#arg.headers)#headers.transfer_encoding),
Priv = deliver_accumulated(Arg, CliSock, no, undefined, stream),
wait_for_streamcontent_pid(Priv, CliSock, Pid);
{websocket, CallbackMod, Opts} ->
+ flush(CliSock, CliDataPos, (Arg#arg.headers)#headers.content_length,
+ (Arg#arg.headers)#headers.transfer_encoding),
%% The handshake passes control over the socket to OwnerPid
%% and terminates the Yaws worker!
yaws_websockets:start(Arg, CallbackMod, Opts);
_ ->
+ flush(CliSock, CliDataPos, (Arg#arg.headers)#headers.content_length,
+ (Arg#arg.headers)#headers.transfer_encoding),
DeliverCont(Arg)
end.

0 comments on commit d09ed3d

Please sign in to comment.