Skip to content
Download

header

mach::Response::header

Returns the value of a response header.

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

[[nodiscard]] std::optional<std::string_view> header(std::string_view name) const;

The header value, or std::nullopt if the response does not contain the specified header.

Parameter Description
name The name of the header to return.
Exception Condition
std::bad_alloc Thrown if memory allocation fails.

Header names are case-insensitive.

This function is thread-safe.

if (auto value = response().header("Content-Type")) {
// Use *value...
}
Name Description
header Sets a response header.
setHeader Sets a response header.
containsHeader Checks whether the response contains a header.