Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces

A cookie is used for exchanging a small amount of information between a HttpPage and a web browser. More...

#include <HttpServer.h>

Public Member Functions

const char * getComment () const
 Returns the comment set for this cookie or null if the cookie comment is not set. More...
 
const char * getDomain () const
 Returns the domain name set for this cookie. More...
 
BaTime getMaxAge () const
 Read the stored cookie lifetime in seconds. More...
 
const char * getName () const
 Returns the name of the cookie. More...
 
const char * getPath () const
 Returns the path on the server to which the browser returns this cookie. More...
 
bool getSecure () const
 Read the cookie's Secure flag. More...
 
bool getHttpOnly () const
 Return the HttpOnly attribute. More...
 
const char * getValue () const
 Returns the value of the cookie. More...
 
int setComment (const char *purpose)
 Specifies a comment that describes a cookie's purpose. More...
 
int setDomain (const char *pattern)
 Specifies the domain within which this cookie should be presented. More...
 
void setMaxAge (BaTime expiry)
 Sets the maximum age of the cookie in seconds. More...
 
void deleteCookie ()
 Specifies a path for the cookie to which the client should return the cookie. More...
 
int setPath (const char *uri)
 Set the cookie path. More...
 
void setSecure (bool flag)
 Inform the browser whether the cookie should be sent only using a secure protocol such as HTTPS – i.e. More...
 
void setHttpOnly (bool flag)
 Marks or unmarks this Cookie as HttpOnly. More...
 
int setValue (const char *newValue)
 Assigns a new value to a cookie after the cookie is created. More...
 
void activate ()
 Activates the cookie. More...
 

Usage and lifecycle

A cookie is used for exchanging a small amount of information between a HttpPage and a web browser.

A cookie's value can uniquely identify a client, so cookies are commonly used for session management.

A cookie has a name, a single value, and optional attributes such as: a comment, path and domain qualifiers, a maximum age, and a version number.

The cookie implementation is almost identical to the cookie implementation in the JavaTM Enterprise Edition

Typical usage:

HttpCookie* cookie = request->getCookie("myCookie");
if( ! cookie ) //If no cookie set for this page
{ //Create a session cookie
cookie = reply->createCookie("myCookie");
//Active cookie i.e. send cookie to client
cookie->activate();
}
//This will never fail
baAssert(cookie == request->getCookie("myCookie"));
void activate()
Activates the cookie.
Definition: HttpServer.h:845
A cookie is used for exchanging a small amount of information between a HttpPage and a web browser.
Definition: HttpServer.h:597

Cookie objects and getter strings are owned by the request/response and expire with it. Do not destroy or free a cookie obtained from the server. String setters copy input; a successful replacement invalidates the old getter pointer. Activate before committing to emit a Set-Cookie header.

Member Function Documentation

◆ getComment()

const char * HttpCookie::getComment ( ) const

Returns the comment set for this cookie or null if the cookie comment is not set.

Returns
The comment set for this cookie or null if the cookie comment is not set.

◆ getDomain()

const char * HttpCookie::getDomain ( ) const

Returns the domain name set for this cookie.

Returns
The domain name set for this cookie.

◆ getHttpOnly()

bool HttpCookie::getHttpOnly ( ) const

Return the HttpOnly attribute.

See also
setHttpOnly.
Returns
The HttpOnly attribute.

◆ getMaxAge()

BaTime HttpCookie::getMaxAge ( ) const

Read the stored cookie lifetime in seconds.

Returns
The configured lifetime. Zero is the default for a newly created session cookie, but also the value after setMaxAge(0) requests deletion; this getter alone does not distinguish those states.
See also
setMaxAge

◆ getName()

const char * HttpCookie::getName ( ) const

Returns the name of the cookie.

Returns
The name of the cookie.

◆ getPath()

const char * HttpCookie::getPath ( ) const

Returns the path on the server to which the browser returns this cookie.

Returns
The path on the server to which the browser returns this cookie.

◆ getSecure()

bool HttpCookie::getSecure ( ) const

Read the cookie's Secure flag.

Returns
True if the cookie is configured for secure transport only; false otherwise. This reports the attribute, not the security of the current request.

◆ getValue()

const char * HttpCookie::getValue ( ) const

Returns the value of the cookie.

Returns
The value of the cookie.