setHeader
mach::Response::setHeader
Sets a response header.
Description
Section titled “Description”Sets the value of the HTTP header with the specified name.
Syntax
Section titled “Syntax”void setHeader(std::string_view name, std::string_view value);Parameters
Section titled “Parameters”| Parameter | Description |
|---|---|
name |
The name of the header to set. |
value |
The value of the header to set. |
Exceptions
Section titled “Exceptions”| 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. |
Remarks
Section titled “Remarks”Header names are case-insensitive.
If the response already contains a header with the specified name, its value is replaced.
Thread Safety
Section titled “Thread Safety”This function is not thread-safe.
Example
Section titled “Example”response().setHeader("Content-Type", "application/json");See Also
Section titled “See Also”| Name | Description |
|---|---|
header |
Returns the value of a response header. |
containsHeader |
Checks whether the response contains a header. |