aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cowboy_req.erl6
-rw-r--r--src/cowboy_static.erl6
-rw-r--r--test/http_handler_stream_body.erl3
3 files changed, 9 insertions, 6 deletions
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index 93993f8..adfb13a 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -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;
_ ->
diff --git a/src/cowboy_static.erl b/src/cowboy_static.erl
index 55d01c7..530c0f9 100644
--- a/src/cowboy_static.erl
+++ b/src/cowboy_static.erl
@@ -321,8 +321,10 @@ content_types_provided(Req, #state{filepath=Filepath,
-spec file_contents(cowboy_req:req(), #state{}) -> tuple().
file_contents(Req, #state{filepath=Filepath,
fileinfo={ok, #file_info{size=Filesize}}}=State) ->
- {ok, Transport, Socket} = cowboy_req:transport(Req),
- Writefile = fun() -> Transport:sendfile(Socket, Filepath) end,
+ Writefile = fun(Socket, Transport) ->
+ {ok, _} = Transport:sendfile(Socket, Filepath),
+ ok
+ end,
{{stream, Filesize, Writefile}, Req, State}.
diff --git a/test/http_handler_stream_body.erl b/test/http_handler_stream_body.erl
index feb4f78..15870a8 100644
--- a/test/http_handler_stream_body.erl
+++ b/test/http_handler_stream_body.erl
@@ -13,8 +13,7 @@ init({_Transport, http}, Req, Opts) ->
{ok, Req, #state{headers=Headers, body=Body, reply=Reply}}.
handle(Req, State=#state{headers=_Headers, body=Body, reply=set_resp}) ->
- {ok, Transport, Socket} = cowboy_req:transport(Req),
- SFun = fun() -> Transport:send(Socket, Body), sent end,
+ SFun = fun(Socket, Transport) -> Transport:send(Socket, Body) end,
SLen = iolist_size(Body),
Req2 = cowboy_req:set_resp_body_fun(SLen, SFun, Req),
{ok, Req3} = cowboy_req:reply(200, Req2),