-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Cowboy version: (e.g. 2.9.0)
Erlang/OTP version: (e.g. OTP 25.2)
Problem
When returning {<<>>, Req, State} after setting response headers, Cowboy does not send the headers.
Example:
Req1 = cowboy_req:set_resp_header(<<"content-type">>, <<"application/x-ndjson">>, Req0),
Req2 = cowboy_req:set_resp_header(<<"x-change-count">>, <<"0">>, Req1),
{<<>>, Req2, State}.
No response headers appear in the client response.
However, if the body is non-empty, e.g.:
Result = <<"line1\n">>,
Req1 = cowboy_req:set_resp_header(<<"content-type">>, <<"application/x-ndjson">>, Req0),
Req2 = cowboy_req:set_resp_header(<<"x-change-count">>, <<"1">>, Req1),
{Result, Req2, State}.
…the headers are included.
Expected Behavior
Setting headers followed by returning a body tuple—even if the body is empty—should result in headers being sent, or Cowboy documentation should clarify the behavior.
Actual Behavior
Returning {<<>>, Req, State} results in no headers being sent, suggesting Cowboy considers this as “no reply yet.”
Question
Is this intended behavior?
If so, what is the correct way to send an empty body with custom headers?