This class holds the response the server is sending back to the client. More...
#include <DcResponse.h>
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. |
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.
Definition at line 55 of file DcResponse.h.
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.
psock | A 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.
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.
(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.
Returns one of the response fields value, or empty string if cannot find the header field name.
name | The name of the field, as a 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.
(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.
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.
name | The name of the cookie, as a BufferHolder. |
val | The value of the cookie, as a BufferHolder. |
days | The number of days this cookie will be valid. This number can be negative (to delete a cookie). 1 is the default. |
path | The 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.
name | The name of this new response header, as a BufferHolder. |
value | The 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.
code | The 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).
vrs | The HTTP version as string. |
Definition at line 269 of file DcResponse.cpp.