Public Member Functions

CdcResponse Class Reference

This class holds the response the server is sending back to the client. More...

#include <DcResponse.h>

Inheritance diagram for CdcResponse:
IdcResponse

List of all members.

Public Member Functions

 CdcResponse (CdcSocket *psock, CdcBuffersList &bflst)
 Constructor - Builds an empty object with default values for the header fields, and attaches a CdcSocket object to it.
virtual ~CdcResponse ()
 Destructor - Does nothing.
int SendResponse () throw (CdcException)
 Send the response to the client.
virtual int Flush (BufferHolder buff) throw (int)
 This function implements IdcResponse::Flush.
void SetVersion (const CdcString &vrs)
 Set the HTTP version for this response (you should not use this function typically).
void SetStatus (int code)
 Set the status code, and phrase for this response.
CdcString GetStatus () const
 Return the status phrase.
void SetHeaderField (const CdcString &name, const CdcString &value)
 Set one of the header fields value.
virtual void SetResponseHeader (BufferHolder name, BufferHolder value)
 SetHeadrField lets a script to add a name-value pair to the response headers list.
CdcString GetHeaderField (CdcString &name)
 Returns one of the response fields value, or empty string if cannot find the header field name.
void SetCookie (const CdcString &name, const CdcString &val, int days=1, const CdcString &path="/")
 Set a cookie in the cookies collection.
virtual void SetResponseCookie (BufferHolder name, BufferHolder val, int days=1, BufferHolder path=BufferHolder("/"))
 SetCookie lets a script to add a cookie to the response headers list.
void Restart ()
 Restart clears all the data from the response except of the connected socket.
virtual void Clear ()
 This function implements IdcResponse::Clear.

Detailed Description

This class holds the response the server is sending back to the client.

The response has header fields and body (the HTML file). the user can set the headers and the data, and then send it by the CdcSocket object attached to this object in the Constructor.

CdcResponse implements the interface IdcResponse. The functions that implement IdcResponse, work with STL string and not CdcString, because scripting engines don't know CdcString. In addition some of the interface functions have a little different names from the implemented class functions, and they call the "real" class function in-line. That is to solve the ambiguity problem of working with STL string and CdcString in the same class.

Author:
Erez Bibi
Version:
1.1

Definition at line 55 of file DcResponse.h.


Constructor & Destructor Documentation

CdcResponse::CdcResponse ( CdcSocket psock,
CdcBuffersList bflst 
)

Constructor - Builds an empty object with default values for the header fields, and attaches a CdcSocket object to it.

Parameters:
psockA pointer to CdcSocket object.

Definition at line 29 of file DcResponse.cpp.

virtual CdcResponse::~CdcResponse (  ) [inline, virtual]

Destructor - Does nothing.

Definition at line 118 of file DcResponse.h.


Member Function Documentation

void CdcResponse::Clear (  ) [virtual]

This function implements IdcResponse::Clear.

it erases all data from the response object, including the parameter buffer pointer, but it does not set isHeaderSent flag to false.

Implements IdcResponse.

Definition at line 40 of file DcResponse.cpp.

int CdcResponse::Flush ( BufferHolder  buff ) throw (int) [virtual]

This function implements IdcResponse::Flush.

It sends the part of the buffers list that is already in, as a chunk response. It sends the headers just once, and set isHeadersSent to True. If 'buff' is not empty, the function sends it as well. After sending everything it calls Clear.

This function implements a Chunk response sending protocol. It is possible to call Flush (for number of times) and then call CdcResponse regular Send in the same session.

Exceptions:
(int)This function will throw an integer value if the socket generate an exception. This is for the script engine.

Implements IdcResponse.

Definition at line 208 of file DcResponse.cpp.

CdcString CdcResponse::GetHeaderField ( CdcString name )

Returns one of the response fields value, or empty string if cannot find the header field name.

Parameters:
nameThe name of the field, as a string.
Returns:
(CdcString) A copy of the value of this field string.

Definition at line 288 of file DcResponse.cpp.

CdcString CdcResponse::GetStatus (  ) const [inline]

Return the status phrase.

Definition at line 167 of file DcResponse.h.

void CdcResponse::Restart (  )

Restart clears all the data from the response except of the connected socket.

So it will be ready for building a new response to the same client. This is for the Keep-Alive feature. After calling Restart, the class will send the response headers again.

Definition at line 47 of file DcResponse.cpp.

int CdcResponse::SendResponse (  ) throw (CdcException)

Send the response to the client.

It sends the header and all body buffers. If a call to Flush has already been made, it calls Flush again to send the rest of the data as chunks, and then sends the end of chunk response string.

Returns:
(int) The length of the response that was actually sent.
Exceptions:
(CdcException)Exceptions from the CdcSocket object.

Definition at line 181 of file DcResponse.cpp.

void CdcResponse::SetCookie ( const CdcString name,
const CdcString val,
int  days = 1,
const CdcString path = "/" 
)

Set a cookie in the cookies collection.

Implementation of IdcResponse::SetCookie

Definition at line 256 of file DcResponse.cpp.

void CdcResponse::SetHeaderField ( const CdcString name,
const CdcString value 
)

Set one of the header fields value.

Implementation of IdcResponse::SetResponseHeader

Definition at line 280 of file DcResponse.cpp.

virtual void CdcResponse::SetResponseCookie ( BufferHolder  name,
BufferHolder  val,
int  days = 1,
BufferHolder  path = BufferHolder("/") 
) [inline, virtual]

SetCookie lets a script to add a cookie to the response headers list.

Parameters:
nameThe name of the cookie, as a BufferHolder.
valThe value of the cookie, as a BufferHolder.
daysThe number of days this cookie will be valid. This number can be negative (to delete a cookie). 1 is the default.
pathThe path of this cookie, as a BufferHolder. "/" is the default.

Implements IdcResponse.

Definition at line 193 of file DcResponse.h.

virtual void CdcResponse::SetResponseHeader ( BufferHolder  name,
BufferHolder  value 
) [inline, virtual]

SetHeadrField lets a script to add a name-value pair to the response headers list.

Parameters:
nameThe name of this new response header, as a BufferHolder.
valueThe value of this header, as a BufferHolder.

Implements IdcResponse.

Definition at line 175 of file DcResponse.h.

void CdcResponse::SetStatus ( int  code )

Set the status code, and phrase for this response.

The function takes the status phrase from a private list.

Parameters:
codeThe status code.

Definition at line 274 of file DcResponse.cpp.

void CdcResponse::SetVersion ( const CdcString vrs )

Set the HTTP version for this response (you should not use this function typically).

Parameters:
vrsThe HTTP version as string.

Definition at line 269 of file DcResponse.cpp.


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