libnavajo
web server for static and dynamic pages developement in C++
Public Member Functions | List of all members
HttpResponse Class Reference

Public Member Functions

 HttpResponse (std::string mime="")
 
void setContent (unsigned char *content, size_t length)
 
void getContent (unsigned char **content, size_t *length, bool *zip)
 
void setIsZipped (bool b=true)
 
bool isZipped () const
 
void addCookie (const std::string &name, const std::string &value, const time_t maxage=0, const time_t expiresTime=0, const std::string &path="/", const std::string &domain="", const bool secure=false, bool httpOnly=false)
 
void addSessionCookie (const std::string &sid)
 
std::vector< std::string > & getCookies ()
 
void setMimeType (const std::string &mime)
 
const std::string & getMimeType () const
 
void forwardTo (const std::string &url)
 
std::string getForwardedUrl ()
 
void setCORS (bool cors=true, bool cred=false, std::string domain="*")
 
bool isCORS ()
 
bool isCORSwithCredentials ()
 
std::string & getCORSdomain ()
 

Member Function Documentation

void HttpResponse::addCookie ( const std::string &  name,
const std::string &  value,
const time_t  maxage = 0,
const time_t  expiresTime = 0,
const std::string &  path = "/",
const std::string &  domain = "",
const bool  secure = false,
bool  httpOnly = false 
)
inline

insert a cookie entry (rfc6265) format: "<name>=<value>[; <Max-Age>=<age>][; expires=<date>] [; domain=<domain_name>][; path=<some_path>][; secure][; HttpOnly]"

Parameters
namethe cookie's name
valuethe cookie's value
maxagethe cookie's max-age
expiresTimethe cookie's expiration date
paththe cookie's path
domainthe cookie's domain
securethe cookie's secure flag
httpOnlythe cookie's httpOnly flag
void HttpResponse::addSessionCookie ( const std::string &  sid)
inline

insert the session's cookie

Parameters
sidthe session id
void HttpResponse::forwardTo ( const std::string &  url)
inline

Request redirection to a new url

Parameters
urlthe new url
void HttpResponse::getContent ( unsigned char **  content,
size_t *  length,
bool *  zip 
)
inline

Returns the response body of the HTTP method

Parameters
contentThe content's buffer
lengthThe content's length
cookiesThe cookies entries
zipset to true if the content is compressed (else: false)
std::vector<std::string>& HttpResponse::getCookies ( )
inline

get the http response's cookies

Returns
the cookies vector
std::string HttpResponse::getForwardedUrl ( )
inline

get the new url

Returns
the new url
const std::string& HttpResponse::getMimeType ( ) const
inline

get the current mime type

Returns
the mime type
bool HttpResponse::isCORS ( )
inline

is Cross Site Request allowed ?

Returns
boolean
bool HttpResponse::isZipped ( ) const
inline

return true if the content is compressed (zip)

void HttpResponse::setContent ( unsigned char *  content,
size_t  length 
)
inline

set the response body

Parameters
contentThe content's buffer
lengthThe content's length
void HttpResponse::setCORS ( bool  cors = true,
bool  cred = false,
std::string  domain = "*" 
)
inline

allow Cross Site Request

Parameters
corsenabled or not
credenabled credentials or not
void HttpResponse::setIsZipped ( bool  b = true)
inline

Set if the content is compressed (zip) or not

Parameters
btrue if the content is compressed, false if not.
void HttpResponse::setMimeType ( const std::string &  mime)
inline

set a new mime type (by default, mime type is automatically set)

Parameters
mimethe new mime type

The documentation for this class was generated from the following file: