Skip to content
Download

cookie

mach::Request::cookie

Returns the value of a request cookie.

Returns the value of the cookie with the specified name.

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

The cookie value, or std::nullopt if the request does not contain the specified cookie.

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

Cookie names are case-sensitive.

This function is thread-safe.

if (auto value = request().cookie("session")) {
// Use *value...
}
Name Description
containsCookie Checks whether the request contains a cookie.