HTTP reply message. More...

#include <tnt/httpreply.h>

Inheritance diagram for tnt::HttpReply:
tnt::HttpMessage

Public Types

enum  Redirect { permanently = HTTP_MOVED_PERMANENTLY, temporarily = HTTP_TEMPORARY_REDIRECT }
- Public Types inherited from tnt::HttpMessage
typedef Messageheader header_type

Public Member Functions

 HttpReply (std::ostream &s, bool sendStatusLine=true)
 ~HttpReply ()
void setContentType (const char *t)
void setContentType (const std::string &t)
const char * getContentType () const
void setHeadRequest (bool sw=true)
void clearSession ()
 Configure the session to be cleared after the current request.
bool isClearSession () const
 Check if the session is configured to be cleared after the current request.
unsigned notAuthorized (const std::string &realm)
 Request authorization from the client.
unsigned notAuthorised (const std::string &realm)
 alias for notAuthorized
void sendReply (unsigned ret, const char *msg="OK")
void sendReply (unsigned ret, const std::string &msg)
std::ostream & out ()
 Get output stream.
std::ostream & sout ()
 Get safe output stream (unsafe html characters written into this stream are escaped)
std::ostream & uout ()
 Get url output stream (everything written into this stream is url-encoded)
void resetContent ()
void rollbackContent (unsigned size)
void setContentLengthHeader (size_t size)
void setKeepAliveHeader ()
void setMaxAgeHeader (unsigned seconds)
virtual void setDirectMode (unsigned ret=HTTP_OK, const char *msg="OK")
virtual void setDirectModeNoFlush ()
virtual bool isDirectMode () const
std::string::size_type getContentSize () const
unsigned chunkedBytesWritten () const
std::ostream & getDirectStream ()
void setChunkedEncoding (unsigned ret=HTTP_OK, const char *msg=0)
 Enable chunked encoding for the current request.
bool isChunkedEncoding () const
 Check whether chunked encoding is enabled.
void setMd5Sum ()
 Sets the content-md5 header.
void setCookie (const std::string &name, const Cookie &value)
void setCookie (const std::string &name, const std::string &value, unsigned seconds)
void setCookies (const Cookies &c)
void clearCookie (const std::string &name)
void clearCookie (const std::string &name, const Cookie &c)
bool hasCookies () const
const CookiesgetCookies () const
void setKeepAliveCounter (unsigned c)
unsigned getKeepAliveCounter () const
void setAcceptEncoding (const Encoding &enc)
bool keepAlive () const
void setLocale (const std::locale &loc)
unsigned redirect (const std::string &newLocation, Redirect type=temporarily)
 Redirect the user to another URL.
unsigned redirectTemporary (const std::string &newLocation)
 Redirect the user to another URL.
unsigned redirectPermantently (const std::string &newLocation)
 Redirect the user to another URL.
- Public Member Functions inherited from tnt::HttpMessage
 HttpMessage ()
virtual ~HttpMessage ()
virtual void clear ()
 Remove all request-specific content.
const char * getHeader (const char *key, const char *def="") const
 Get the content of the specified header if it is set, the passed default otherwise.
unsigned short getMajorVersion () const
 Get the major http version number.
unsigned short getMinorVersion () const
 Get the minor http version number.
void setVersion (unsigned short majorVersion, unsigned short minorVersion)
 Set the http version number.
header_type::const_iterator header_begin () const
 Get a constant iterator which points to the first header.
header_type::const_iterator header_end () const
 Get a constant iterator which points past the last header.
void setHeader (const std::string &key, const std::string &value, bool replace=true)
 Add the specified header to the message.
void removeHeader (const std::string &key)
 Remove the specified header from the message.
std::string dumpHeader () const
 Get all headers in one string.
void dumpHeader (std::ostream &out) const
 Print all headers to the specified output stream.
bool hasHeader (const char *key) const
bool hasHeader (const std::string &key) const

Static Public Member Functions

static bool tryCompress (std::string &body)
static void postRunCleanup ()
- Static Public Member Functions inherited from tnt::HttpMessage
static std::string htdateCurrent ()
 Get a string for the current time, formatted as needed in http.
static void htdateCurrent (char *current)
 Get a string for the current time, formatted as needed in http buffer must point to at least 30 bytes.
static bool checkUrl (const std::string &url)
 Check for double-dot-url.
static std::string htdate (time_t t)
static std::string htdate (const struct::tm *tm)
static void htdate (char *date, time_t t)
static void htdate (char *date, const struct::tm *tm)

Additional Inherited Members

- Protected Attributes inherited from tnt::HttpMessage
header_type header
Cookies httpcookies

Detailed Description

HTTP reply message.

Member Enumeration Documentation

Enumerator:
permanently 
temporarily 

Constructor & Destructor Documentation

tnt::HttpReply::HttpReply ( std::ostream &  s,
bool  sendStatusLine = true 
)
explicit
tnt::HttpReply::~HttpReply ( )

Member Function Documentation

unsigned tnt::HttpReply::chunkedBytesWritten ( ) const
void tnt::HttpReply::clearCookie ( const std::string &  name)
void tnt::HttpReply::clearCookie ( const std::string &  name,
const Cookie c 
)
inline
void tnt::HttpReply::clearSession ( )

Configure the session to be cleared after the current request.

std::string::size_type tnt::HttpReply::getContentSize ( ) const
const char* tnt::HttpReply::getContentType ( ) const
inline
const Cookies& tnt::HttpReply::getCookies ( ) const
inline
std::ostream& tnt::HttpReply::getDirectStream ( )
unsigned tnt::HttpReply::getKeepAliveCounter ( ) const
bool tnt::HttpReply::hasCookies ( ) const
inline
bool tnt::HttpReply::isChunkedEncoding ( ) const

Check whether chunked encoding is enabled.

bool tnt::HttpReply::isClearSession ( ) const

Check if the session is configured to be cleared after the current request.

virtual bool tnt::HttpReply::isDirectMode ( ) const
virtual
bool tnt::HttpReply::keepAlive ( ) const
unsigned tnt::HttpReply::notAuthorised ( const std::string &  realm)
inline

alias for notAuthorized

unsigned tnt::HttpReply::notAuthorized ( const std::string &  realm)

Request authorization from the client.

This will result in a dialog being shown in the user's web browser.

std::ostream& tnt::HttpReply::out ( )
inline

Get output stream.

static void tnt::HttpReply::postRunCleanup ( )
static
unsigned tnt::HttpReply::redirect ( const std::string &  newLocation,
Redirect  type = temporarily 
)

Redirect the user to another URL.

This function never returns as it throws an exception to actually send the redirect header.

unsigned tnt::HttpReply::redirectPermantently ( const std::string &  newLocation)
inline

Redirect the user to another URL.

This function never returns as it throws an exception to actually send the redirect header.

unsigned tnt::HttpReply::redirectTemporary ( const std::string &  newLocation)
inline

Redirect the user to another URL.

This function never returns as it throws an exception to actually send the redirect header.

void tnt::HttpReply::resetContent ( )
void tnt::HttpReply::rollbackContent ( unsigned  size)
void tnt::HttpReply::sendReply ( unsigned  ret,
const char *  msg = "OK" 
)
void tnt::HttpReply::sendReply ( unsigned  ret,
const std::string &  msg 
)
inline
void tnt::HttpReply::setAcceptEncoding ( const Encoding enc)
void tnt::HttpReply::setChunkedEncoding ( unsigned  ret = HTTP_OK,
const char *  msg = 0 
)

Enable chunked encoding for the current request.

When enabling chunked encoding, the content is sent immediately in chunks instead of collecting content into a string before sending. After enabling chunked encoding, it must be ensured that no exceptions are thrown. Also, headers are sent immediately after enabling chunked encoding and hence setting headers must happen before calling this method.

Furthermore, session cookies cannot be sent with chunked encoding enabled, hence when a new session is created, chunked encoding must not be used. Sessions are created automatically when a session variable is used and no session cookie was received.

void tnt::HttpReply::setContentLengthHeader ( size_t  size)
void tnt::HttpReply::setContentType ( const char *  t)
inline
void tnt::HttpReply::setContentType ( const std::string &  t)
inline
void tnt::HttpReply::setCookie ( const std::string &  name,
const Cookie value 
)
void tnt::HttpReply::setCookie ( const std::string &  name,
const std::string &  value,
unsigned  seconds 
)
inline
void tnt::HttpReply::setCookies ( const Cookies c)
inline
virtual void tnt::HttpReply::setDirectMode ( unsigned  ret = HTTP_OK,
const char *  msg = "OK" 
)
virtual
virtual void tnt::HttpReply::setDirectModeNoFlush ( )
virtual
void tnt::HttpReply::setHeadRequest ( bool  sw = true)
void tnt::HttpReply::setKeepAliveCounter ( unsigned  c)
void tnt::HttpReply::setKeepAliveHeader ( )
void tnt::HttpReply::setLocale ( const std::locale &  loc)
inline
void tnt::HttpReply::setMaxAgeHeader ( unsigned  seconds)
void tnt::HttpReply::setMd5Sum ( )

Sets the content-md5 header.

The current content is used to calculate the md5 header. Hence no output must be created after calling that method. Normally there is no good reason to call that method at all.

std::ostream& tnt::HttpReply::sout ( )
inline

Get safe output stream (unsafe html characters written into this stream are escaped)

static bool tnt::HttpReply::tryCompress ( std::string &  body)
static
std::ostream& tnt::HttpReply::uout ( )
inline

Get url output stream (everything written into this stream is url-encoded)


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