Cookie
mach::http::Cookie
Description
Section titled “Description”Represents an HTTP cookie and its associated attributes.
Headers
Section titled “Headers”Primary header:
#include <mach/http/Cookie.hpp>Convenience header:
#include <mach/mach.hpp>Syntax
Section titled “Syntax”struct Cookie { std::string name; std::string value;
std::string path = "/"; std::optional<std::string> domain;
std::optional<std::chrono::system_clock::time_point> expires; std::optional<std::chrono::seconds> maxAge;
SameSite sameSite = SameSite::Lax;
bool secure = false; bool httpOnly = false;};Data Members
Section titled “Data Members”| Name | Description |
|---|---|
name |
Cookie name. |
value |
Cookie value. |
path |
Limits the cookie to requests under the specified path. Defaults to /. |
domain |
Restricts the cookie to the specified domain. |
expires |
Absolute expiration time of the cookie. |
maxAge |
Relative lifetime of the cookie. |
sameSite |
Controls when the cookie is sent with cross-site requests. Defaults to SameSite::Lax. |
secure |
Sends the cookie only over HTTPS when true. |
httpOnly |
Prevents client-side JavaScript from accessing the cookie when true. |
Thread Safety
Section titled “Thread Safety”Not thread-safe. Concurrent access to the same Cookie instance must be synchronized externally.
Remarks
Section titled “Remarks”- path defaults to /, sameSite defaults to SameSite::Lax, and secure and httpOnly default to false.
- Cookie names are case-sensitive.
- Multiple cookies with the same name may exist in a response. Each call to Response::addCookie() appends a new Set-Cookie header.
Example
Section titled “Example”mach::http::Cookie cookie{ .name = "theme", .value = "dark", .path = "/", .sameSite = mach::http::SameSite::Lax, .httpOnly = true,};See Also
Section titled “See Also”| Name | Description |
|---|---|
Request |
Represents the current HTTP request. |
Response |
Represents the HTTP response being built. |
SameSite |
Specifies the cookie’s cross-site behavior. |