Skip to content
Download

setHeader

mach::Response::setHeader

Sets a response header.

Sets the value of the HTTP header with the specified name.

void setHeader(std::string_view name, std::string_view value);
Parameter Description
name The name of the header to set.
value The value of the header to set.
Exception Condition
std::invalid_argument Thrown if the header name is empty, contains characters not permitted in HTTP header field names, or is a reserved header.

Header names are case-insensitive.

If the response already contains a header with the specified name, its value is replaced.

This function is not thread-safe.

response().setHeader("Content-Type", "application/json");
Name Description
header Returns the value of a response header.
containsHeader Checks whether the response contains a header.