Skip to content
Download

header

mach::Request::header

Returns the value of a request 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 request 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 = request().header("Authorization")) {
// Use *value...
}
Name Description
containsHeader Checks whether the request contains a header.