Skip to content
This repository was archived by the owner on Mar 13, 2019. It is now read-only.

Repository files navigation

cookie

Cookie support for Mana. Following RFC 6265.

Example service:Acorn Web Server Appliance with its routes that use cookies.

Features

  • Create, update and clear cookies
  • Easy access to an incoming request's existing cookies

Usage

Create a cookie with a name and value on the response:

res->cookie(Cookie{"lang", "nb-NO"});
// Or if you want to create a cookie with more options, f.ex. expires, path and domain:
res->cookie(Cookie{"lang", "nb-NO", {"Expires", "Sun, 11 Dec 2016 08:49:37 GMT",
"Path", "/path", "Domain", "domain.com"}});

Update an existing cookie's value:

res->update_cookie<Cookie>("lang", "en-US");
// Or if you have specified a path and/or domain when creating the cookie:
res->update_cookie<Cookie>("lang", "/path", "domain.com", "en-US");

Clear a cookie:

res->clear_cookie<Cookie>("lang");
// Or if you have specified a path and/or domain when creating the cookie:
res->clear_cookie<Cookie>("lang", "/path", "domain.com");

The cookie library contains the middleware CookieParser that parses a request's cookie header and puts the cookies in a CookieJar. The CookieJar is then added as an attribute to the request, making the cookies available to the developer:

if (req->has_attribute<CookieJar>()) {
// Get the CookieJarauto req_cookies = req->get_attribute<CookieJar>();
{ // Print all the request-cookies (name-value pairs)constauto& all_cookies = req_cookies->get_cookies();
for (constauto& c : all_cookies)
printf("Cookie: %s=%s\n", c.first.c_str(), c.second.c_str());
}
// Get the value of a cookie named langconstauto& value = req_cookies->cookie_value("lang");
// Do actions based on the value
}

Requirements

About

Cookie support for Mana *omnomnom*

Resources

Stars

2 stars

Watchers

4 watching

Forks

Releases

Packages

Contributors

Languages