chttpserver · Section 3
chttpsvr_resp_set_status
NAME
chttpsvr_resp_set_status - set the HTTP response status code
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/chttpserver.h> void chttpsvr_resp_set_status(chttpsvr_resp *resp, int status_code);
DESCRIPTION
Sets the HTTP status code of the response. The default is 200. The value is stored exactly as given, with no check here. When the server sends the response, a value outside the range of final status codes, 200 to 999, goes on the wire as 500 Internal Server Error, although the stored value stays what you set. A 1xx falls in that case too: It is an interim status (RFC 9110 15.2), and a client that got one as the response would keep waiting for a final status. The server writes the interim "100 Continue" itself.
NOTES
With a status_code of 204, 205 or 304 the response body is dropped on the wire, including anything that chttpsvr_resp_write, chttpsvr_resp_write_str, chttpsvr_resp_printf or chttpsvr_resp_write_json has already written, since RFC 9110 6.4.1, 15.3.6 and 15.4.5 forbid a body for these codes. A 205 carries "content-length:0", a 204 carries no Content-Length, and a 304 carries the one that the handler set, if it set one. See the NOTES section of chttpsvr_resp_write(3). The status line carries the reason phrase that the IANA HTTP Status Code Registry gives the code, such as "Reset Content" for 205, and "Unknown" for a code the registry does not list. Clients ignore the phrase.