Skip to content
Download

Cookie

mach::http::Cookie

Represents an HTTP cookie and its associated attributes.

Primary header:

#include <mach/http/Cookie.hpp>

Convenience header:

#include <mach/mach.hpp>
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;
};
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.

Not thread-safe. Concurrent access to the same Cookie instance must be synchronized externally.

  • 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.
mach::http::Cookie cookie{
.name = "theme",
.value = "dark",
.path = "/",
.sameSite = mach::http::SameSite::Lax,
.httpOnly = true,
};
Name Description
Request Represents the current HTTP request.
Response Represents the HTTP response being built.
SameSite Specifies the cookie’s cross-site behavior.