header
mach::Response::header
Returns the value of a response header.
Description
Section titled “Description”Returns the value of the HTTP header with the specified name.
Syntax
Section titled “Syntax”[[nodiscard]] std::optional<std::string_view> header(std::string_view name) const;Return Value
Section titled “Return Value”The header value, or std::nullopt if the response does not contain the specified header.
Parameters
Section titled “Parameters”| Parameter | Description |
|---|---|
name |
The name of the header to return. |
Exceptions
Section titled “Exceptions”| Exception | Condition |
|---|---|
std::bad_alloc |
Thrown if memory allocation fails. |
Remarks
Section titled “Remarks”Header names are case-insensitive.
Thread Safety
Section titled “Thread Safety”This function is thread-safe.
Example
Section titled “Example”if (auto value = response().header("Content-Type")) { // Use *value...}See Also
Section titled “See Also”| Name | Description |
|---|---|
header |
Sets a response header. |
setHeader |
Sets a response header. |
containsHeader |
Checks whether the response contains a header. |