| 1 |
= cowboy_req:stream_trailers(3) |
| 2 |
|
| 3 |
== Name |
| 4 |
|
| 5 |
cowboy_req:stream_trailers - Send the response trailers |
| 6 |
|
| 7 |
== Description |
| 8 |
|
| 9 |
[source,erlang] |
| 10 |
---- |
| 11 |
stream_trailers(Trailers, Req :: cowboy_req:req()) -> ok |
| 12 |
|
| 13 |
Trailers :: cowboy:http_headers() |
| 14 |
---- |
| 15 |
|
| 16 |
Send the response trailers and terminate the stream. |
| 17 |
|
| 18 |
This function can only be called once, after initiating |
| 19 |
a response using |
| 20 |
link:man:cowboy_req:stream_reply(3)[cowboy_req:stream_reply(3)] |
| 21 |
and sending zero or more body chunks using |
| 22 |
link:man:cowboy_req:stream_body(3)[cowboy_req:stream_body(3)] |
| 23 |
with the `nofin` argument set. The function `stream_trailers/2` |
| 24 |
implies `fin` and automatically terminate the response. |
| 25 |
|
| 26 |
You must list all field names sent in trailers in the |
| 27 |
trailer header, otherwise they might be dropped by intermediaries |
| 28 |
or clients. |
| 29 |
|
| 30 |
== Arguments |
| 31 |
|
| 32 |
Trailers:: |
| 33 |
|
| 34 |
Trailer field values to be sent. |
| 35 |
|
| 36 |
Req:: |
| 37 |
|
| 38 |
The Req object. |
| 39 |
|
| 40 |
== Return value |
| 41 |
|
| 42 |
The atom `ok` is always returned. It can be safely ignored. |
| 43 |
|
| 44 |
== Changelog |
| 45 |
|
| 46 |
* *2.2*: Function introduced. |
| 47 |
|
| 48 |
== Examples |
| 49 |
|
| 50 |
.Stream a response body with trailers |
| 51 |
[source,erlang] |
| 52 |
---- |
| 53 |
Req = cowboy_req:stream_reply(200, #{ |
| 54 |
<<"content-type">> => <<"text/plain">>, |
| 55 |
<<"trailer">> => <<"expires, content-md5">> |
| 56 |
}, Req0), |
| 57 |
cowboy_req:stream_body(<<"Hello\n">>, nofin, Req), |
| 58 |
timer:sleep(1000), |
| 59 |
cowboy_req:stream_body(<<"World!\n">>, nofin, Req). |
| 60 |
cowboy_req:stream_trailers(#{ |
| 61 |
<<"expires">> => <<"Sun, 10 Dec 2017 19:13:47 GMT">>, |
| 62 |
<<"content-md5">> => <<"fbf68a8e34b2ded53bba54e68794b4fe">> |
| 63 |
}, Req). |
| 64 |
---- |
| 65 |
|
| 66 |
== See also |
| 67 |
|
| 68 |
link:man:cowboy_req(3)[cowboy_req(3)], |
| 69 |
link:man:cowboy_req:stream_reply(3)[cowboy_req:stream_reply(3)], |
| 70 |
link:man:cowboy_req:stream_body(3)[cowboy_req:stream_body(3)], |
| 71 |
link:man:cowboy_req:stream_events(3)[cowboy_req:stream_events(3)] |