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

Detailed Description

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:818
A cookie is used for exchanging a small amount of information between a HttpPage and a web browser.
Definition: HttpServer.h:589

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.

#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
 Returns the maximum age of the cookie, specified in seconds; by default, 0 indicating the cookie will persist until browser shutdown. 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
 Returns true if the browser is sending cookies only over a secure protocol, or false if the browser can send cookies using any protocol. 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...
 

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.

◆ getDomain()

const char * HttpCookie::getDomain ( ) const

Returns the domain name set for this cookie.

◆ getHttpOnly()

bool HttpCookie::getHttpOnly ( ) const

Return the HttpOnly attribute.

See also
setHttpOnly.

◆ getMaxAge()

BaTime HttpCookie::getMaxAge ( ) const

Returns the maximum age of the cookie, specified in seconds; by default, 0 indicating the cookie will persist until browser shutdown.

◆ getName()

const char * HttpCookie::getName ( ) const

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.

◆ getSecure()

bool HttpCookie::getSecure ( ) const

Returns true if the browser is sending cookies only over a secure protocol, or false if the browser can send cookies using any protocol.

◆ getValue()

const char * HttpCookie::getValue ( ) const

Returns the value of the cookie.