stream_trailers(Trailers, Req :: cowboy_req:req()) -> ok Trailers :: cowboy:http_headers()
cowboy_req:stream_trailers - Send the response trailers
stream_trailers(Trailers, Req :: cowboy_req:req()) -> ok Trailers :: cowboy:http_headers()
Send the response trailers and terminate the stream.
This function can only be called once, after initiating a response using cowboy_req:stream_reply(3) and sending zero or more body chunks using cowboy_req:stream_body(3) with the nofin
argument set. The function stream_trailers/2
implies fin
and automatically terminate the response.
You must list all field names sent in trailers in the trailer header, otherwise they might be dropped by intermediaries or clients.
Trailer field values to be sent.
The Req object.
The atom ok
is always returned. It can be safely ignored.
Req = cowboy_req:stream_reply(200, #{ <<"content-type">> => <<"text/plain">>, <<"trailer">> => <<"expires, content-md5">> }, Req0), cowboy_req:stream_body(<<"Hello\n">>, nofin, Req), timer:sleep(1000), cowboy_req:stream_body(<<"World!\n">>, nofin, Req). cowboy_req:stream_trailers(#{ <<"expires">> => <<"Sun, 10 Dec 2017 19:13:47 GMT">>, <<"content-md5">> => <<"fbf68a8e34b2ded53bba54e68794b4fe">> }, Req).
cowboy_req(3), cowboy_req:stream_reply(3), cowboy_req:stream_body(3), cowboy_req:stream_events(3)
Donate to Loïc Hoguin because his work on Cowboy, Ranch, Gun and Erlang.mk is fantastic:
Recurring payment options are also available via GitHub Sponsors. These funds are used to cover the recurring expenses like food, dedicated servers or domain names.