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