0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-16 05:00:24 +00:00

Change the response body streaming fun interface

Before we were required to get the socket and transport ourselves,
now they're passed to the function.
This commit is contained in:
Loïc Hoguin 2013-01-05 20:19:43 +01:00
parent d8be610d4c
commit 58e89e2189
3 changed files with 9 additions and 6 deletions

View file

@ -123,7 +123,7 @@
-type cookie_opts() :: [cookie_option()].
-export_type([cookie_opts/0]).
-type resp_body_fun() :: fun(() -> {sent, non_neg_integer()}).
-type resp_body_fun() :: fun((inet:socket(), module()) -> ok).
-record(http_req, {
%% Transport.
@ -876,6 +876,7 @@ reply(Status, Headers, Req=#http_req{resp_body=Body}) ->
iodata() | {non_neg_integer() | resp_body_fun()}, Req)
-> {ok, Req} when Req::req().
reply(Status, Headers, Body, Req=#http_req{
socket=Socket, transport=Transport,
version=Version, connection=Connection,
method=Method, resp_state=waiting, resp_headers=RespHeaders}) ->
RespConn = response_connection(Headers, Connection),
@ -890,7 +891,8 @@ reply(Status, Headers, Body, Req=#http_req{
{<<"date">>, cowboy_clock:rfc1123()},
{<<"server">>, <<"Cowboy">>}
|HTTP11Headers], <<>>, Req),
if RespType =/= hook, Method =/= <<"HEAD">> -> BodyFun();
if RespType =/= hook, Method =/= <<"HEAD">> ->
BodyFun(Socket, Transport);
true -> ok
end;
_ ->