diff options
author | Loïc Hoguin <[email protected]> | 2016-12-21 15:47:44 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2016-12-21 15:47:44 +0100 |
commit | ba14cf783820deb52ea0a810dd457ee179d7e30d (patch) | |
tree | f71d6ffe63e46c6d0a46088beb773c5661982562 /doc/src/manual/cowboy_req.stream_body.asciidoc | |
parent | f57dd51e0f233df60c670009d83fb37058b765f2 (diff) | |
download | cowboy-ba14cf783820deb52ea0a810dd457ee179d7e30d.tar.gz cowboy-ba14cf783820deb52ea0a810dd457ee179d7e30d.tar.bz2 cowboy-ba14cf783820deb52ea0a810dd457ee179d7e30d.zip |
Add man pages for the reply functions
Diffstat (limited to 'doc/src/manual/cowboy_req.stream_body.asciidoc')
-rw-r--r-- | doc/src/manual/cowboy_req.stream_body.asciidoc | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/doc/src/manual/cowboy_req.stream_body.asciidoc b/doc/src/manual/cowboy_req.stream_body.asciidoc new file mode 100644 index 0000000..e0dbd59 --- /dev/null +++ b/doc/src/manual/cowboy_req.stream_body.asciidoc @@ -0,0 +1,77 @@ += cowboy_req:stream_body(3) + +== Name + +cowboy_req:stream_body - Stream the response body + +== Description + +[source,erlang] +---- +stream_body(Data, IsFin, Req :: cowboy_req:req()) -> ok + +Data :: iodata() +IsFin :: fin | nofin +---- + +Stream the response body. + +This function may be called as many times as needed after +initiating a response using the +link:man:cowboy_req:stream_reply(3)[cowboy_req:stream_reply(3)] +function. + +The second argument indicates if this call is the final +call. Use the `nofin` value until you know no more data +will be sent. The final call should use `fin` (possibly +with an empty data value). + +Note that not using `fin` for the final call is not an +error; Cowboy will take care of it when the request +handler terminates if needed. Depending on the resource +it may however be more efficient to do it as early as +possible. + +You do not need to handle HEAD requests specifically as +Cowboy will ensure no data is sent when you call this function. + +== Arguments + +Data:: + +The data to be sent. + +IsFin:: + +A flag indicating whether this is the final piece of data +to be sent. + +Req:: + +The Req object. + +== Return value + +The atom `ok` is always returned. It can be safely ignored. + +== Changelog + +* *2.0*: Function introduced. Replaces `chunk/2`. + +== Examples + +.Stream the response body +[source,erlang] +---- +Req = cowboy_req:stream_reply(200, #{ + <<"content-type">> => <<"text/plain">> +}, Req0), +cowboy_req:stream_body(<<"Hello\n">>, nofin, Req), +timer:sleep(1000), +cowboy_req:stream_body(<<"World!\n">>, fin, Req). +---- + +== See also + +link:man:cowboy_req(3)[cowboy_req(3)], +link:man:cowboy_req:stream_reply(3)[cowboy_req:stream_reply(3)] |