aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_rest.erl
diff options
context:
space:
mode:
authorJames Fish <[email protected]>2013-02-18 21:20:36 +0000
committerJames Fish <[email protected]>2013-04-26 21:02:10 +0100
commitc8242ab396db2fab7468fd5b0eaac54b5c8f3f39 (patch)
treed640bc6204fc316822d03c744e0982a45151ad45 /src/cowboy_rest.erl
parent46b2ea0aaa7fe891bfdf3f8a0c47357393e72cf6 (diff)
downloadcowboy-c8242ab396db2fab7468fd5b0eaac54b5c8f3f39.tar.gz
cowboy-c8242ab396db2fab7468fd5b0eaac54b5c8f3f39.tar.bz2
cowboy-c8242ab396db2fab7468fd5b0eaac54b5c8f3f39.zip
Add chunked response body fun
Adds a new type of streaming response fun. It can be set in a similar way to a streaming body fun with known length: Req2 = cowboy_req:set_resp_body_fun(chunked, StreamFun, Req) The fun, StreamFun, should accept a fun as its single argument. This fun, ChunkFun, is used to send chunks of iodata: ok = ChunkFun(IoData) ChunkFun should not be called with an empty binary or iolist as this will cause HTTP 1.1 clients to believe the stream is over. The final (0 length) chunk will be sent automatically - even if it has already been sent - assuming no exception is raised. Also note that the connection will close after the last chunk for HTTP 1.0 clients.
Diffstat (limited to 'src/cowboy_rest.erl')
-rw-r--r--src/cowboy_rest.erl2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/cowboy_rest.erl b/src/cowboy_rest.erl
index 4ba2b47..d3e8d7e 100644
--- a/src/cowboy_rest.erl
+++ b/src/cowboy_rest.erl
@@ -945,6 +945,8 @@ set_resp_body(Req, State=#state{handler=Handler, handler_state=HandlerState,
cowboy_req:set_resp_body_fun(StreamFun, Req2);
{stream, Len, StreamFun} ->
cowboy_req:set_resp_body_fun(Len, StreamFun, Req2);
+ {chunked, StreamFun} ->
+ cowboy_req:set_resp_body_fun(chunked, StreamFun, Req2);
_Contents ->
cowboy_req:set_resp_body(Body, Req2)
end,