aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_handler_stream_body.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-01-05 23:35:30 +0100
committerLoïc Hoguin <[email protected]>2013-01-05 23:35:30 +0100
commitfaeb37ed80e1f2ae2bfa0c096b2a660c271adddb (patch)
tree966151c289b7bac75d25c5749c50d5eb1b3f89f8 /test/http_handler_stream_body.erl
parent6edea1c12389444ce05e73733140591e49f6ee86 (diff)
downloadcowboy-faeb37ed80e1f2ae2bfa0c096b2a660c271adddb.tar.gz
cowboy-faeb37ed80e1f2ae2bfa0c096b2a660c271adddb.tar.bz2
cowboy-faeb37ed80e1f2ae2bfa0c096b2a660c271adddb.zip
Add cowboy_req:set_resp_body_fun/2
This allows streaming a body without knowing the length in advance. Also allows {stream, StreamFun} response body in the REST code.
Diffstat (limited to 'test/http_handler_stream_body.erl')
-rw-r--r--test/http_handler_stream_body.erl11
1 files changed, 8 insertions, 3 deletions
diff --git a/test/http_handler_stream_body.erl b/test/http_handler_stream_body.erl
index 15870a8..d8f7d91 100644
--- a/test/http_handler_stream_body.erl
+++ b/test/http_handler_stream_body.erl
@@ -12,10 +12,15 @@ init({_Transport, http}, Req, Opts) ->
Reply = proplists:get_value(reply, Opts),
{ok, Req, #state{headers=Headers, body=Body, reply=Reply}}.
-handle(Req, State=#state{headers=_Headers, body=Body, reply=set_resp}) ->
+handle(Req, State=#state{headers=_Headers, body=Body, reply=Reply}) ->
SFun = fun(Socket, Transport) -> Transport:send(Socket, Body) end,
- SLen = iolist_size(Body),
- Req2 = cowboy_req:set_resp_body_fun(SLen, SFun, Req),
+ Req2 = case Reply of
+ set_resp ->
+ SLen = iolist_size(Body),
+ cowboy_req:set_resp_body_fun(SLen, SFun, Req);
+ set_resp_close ->
+ cowboy_req:set_resp_body_fun(SFun, Req)
+ end,
{ok, Req3} = cowboy_req:reply(200, Req2),
{ok, Req3, State}.