EHS Embedded HTTP Server  1.5.1.0
HttpResponse Class Reference

This class represents what is sent back to the client. More...

#include <httpresponse.h>

+ Inheritance diagram for HttpResponse:
+ Collaboration diagram for HttpResponse:

Public Member Functions

 HttpResponse (int inResponseId, EHSConnection *ipoEHSConnection)
 Constructs a new instance. More...
 
virtual ~HttpResponse ()
 Destructor.
 
void SetBody (const char *ipsBody, size_t inBodyLength)
 Sets the body of this instance. More...
 
void SetCookie (CookieParameters &iroCookieParameters)
 Sets cookies for this response. More...
 
void SetResponseCode (ResponseCode code)
 Sets the response code for this response. More...
 
ResponseCode GetResponseCode ()
 Retrieves the status code of this this response.
 
StringCaseMap & GetHeaders ()
 Retrieves the headers of this this response.
 
StringList & GetCookies ()
 Retrieves the cookies of this this response.
 
void SetHeader (const std::string &name, const std::string &value)
 Sets an HTTP header. More...
 
void RemoveHeader (const std::string &name)
 Removes an HTTP header. More...
 
std::string GetStatusString ()
 Retrieves the status string of this this response. More...
 
void SetDate (time_t stamp)
 Sets the HTTP Date header. More...
 
void SetLastModified (time_t stamp)
 Sets the HTTP Last-Modified header. More...
 
std::string HttpTime (time_t stamp)
 Utility function for converting a UNIX timestamp into an RFC-conformant HTTP time string. More...
 
std::string Header (const std::string &name)
 Retrieves a specific HTTP header. More...
 
- Public Member Functions inherited from GenericResponse
 GenericResponse (int inResponseId, EHSConnection *ipoEHSConnection)
 Constructs a new instance. More...
 
void SetBody (const char *ipsBody, size_t inBodyLength)
 Sets the body of this instance. More...
 
std::string & GetBody ()
 retrieves the body of this response. More...
 
EHSConnectionGetConnection ()
 retrieves the EHSConnection, on which this response is supposed to be send. More...
 
virtual ~GenericResponse ()
 Destructor.
 
void EnableIdleTimeout (bool enable=true)
 Enable/Disable idle-timeout handling for the current connection. More...
 
void EnableKeepAlive (bool enable=true)
 Enable/Disable TCP keepalive on the underlying socket of the current connection. More...
 

Static Public Member Functions

static HttpResponseError (ResponseCode code, int inResponseId, EHSConnection *ipoEHSConnection)
 Constructs a new standardized error response. More...
 
static HttpResponseError (ResponseCode code, HttpRequest *request)
 Constructs a new standardized error response. More...
 
static const char * GetPhrase (ResponseCode code)
 Helper function for translating response codes into the corresponding text message. More...
 

Additional Inherited Members

- Protected Attributes inherited from GenericResponse
int m_nResponseId
 response id for making sure we send responses in the right order
 
std::string m_sBody
 the actual body to be sent back
 
EHSConnectionm_poEHSConnection
 ehs connection object this response goes back on
 

Detailed Description

This class represents what is sent back to the client.

It contains the actual body, any headers specified, and the response code.

Examples:
ehs_basicauth.cpp, ehs_exception.cpp, ehs_formtest.cpp, ehs_mirror.cpp, ehs_privport.cpp, ehs_test.cpp, ehs_testharness.cpp, ehs_uploader.cpp, and ehs_wsgate.cpp.

Definition at line 54 of file httpresponse.h.

Constructor & Destructor Documentation

◆ HttpResponse()

HttpResponse ( int  inResponseId,
EHSConnection ipoEHSConnection 
)

Constructs a new instance.

Parameters
inResponseIdA unique Id (normally derived from the corresponding request Id).
ipoEHSConnectionThe connection, on which this response should be sent.

Member Function Documentation

◆ Error() [1/2]

static HttpResponse* Error ( ResponseCode  code,
int  inResponseId,
EHSConnection ipoEHSConnection 
)
static

Constructs a new standardized error response.

Parameters
codeThe HTTP error code.
inResponseIdA unique Id (normally derived from the corresponding request Id).
ipoEHSConnectionThe connection, on which this response should be sent.
Returns
The new response.
Examples:
ehs_exception.cpp, and ehs_wsgate.cpp.

◆ Error() [2/2]

static HttpResponse* Error ( ResponseCode  code,
HttpRequest request 
)
static

Constructs a new standardized error response.

Parameters
codeThe HTTP error code.
requestThe http request to which this response refers. (Used for initializing the Id and the outgoing connection).
Returns
The new response.

◆ GetPhrase()

static const char* GetPhrase ( ResponseCode  code)
static

Helper function for translating response codes into the corresponding text message.

Parameters
codeThe HTTP result code to be translated.
Returns
The text message, representing the provided result code.

◆ GetStatusString()

std::string GetStatusString ( )

Retrieves the status string of this this response.

Returns
The current status as "<i>number</i> <i>description</i>".

Referenced by RemoveHeader().

+ Here is the caller graph for this function:

◆ Header()

std::string Header ( const std::string &  name)
inline

Retrieves a specific HTTP header.

Parameters
nameThe name of the HTTP header to be retrieved.
Returns
The value of the specified header.

Definition at line 182 of file httpresponse.h.

◆ HttpTime()

std::string HttpTime ( time_t  stamp)

Utility function for converting a UNIX timestamp into an RFC-conformant HTTP time string.

Parameters
stampA UNIX timestamp, representing the desired time.
Returns
A string, containing the HTTP time.

Referenced by RemoveHeader().

+ Here is the caller graph for this function:

◆ RemoveHeader()

void RemoveHeader ( const std::string &  name)
inline

Removes an HTTP header.

Parameters
nameThe case insensitive name of the HTTP header to remove.
Examples:
ehs_wsgate.cpp.

Definition at line 146 of file httpresponse.h.

References GetStatusString(), HttpTime(), SetDate(), and SetLastModified().

+ Here is the call graph for this function:

◆ SetBody()

void SetBody ( const char *  ipsBody,
size_t  inBodyLength 
)

Sets the body of this instance.

Parameters
ipsBodyThe content to set.
inBodyLengthThe length of the body. This parameter also sets the value of the Content-Length HTTP header.
Examples:
ehs_basicauth.cpp, ehs_exception.cpp, ehs_formtest.cpp, ehs_mirror.cpp, ehs_privport.cpp, ehs_test.cpp, ehs_testharness.cpp, ehs_uploader.cpp, and ehs_wsgate.cpp.

Referenced by ~HttpResponse().

+ Here is the caller graph for this function:

◆ SetCookie()

void SetCookie ( CookieParameters &  iroCookieParameters)

Sets cookies for this response.

Parameters
iroCookieParametersThe cookies to set.
Examples:
ehs_test.cpp, and ehs_uploader.cpp.

Referenced by ~HttpResponse().

+ Here is the caller graph for this function:

◆ SetDate()

void SetDate ( time_t  stamp)

Sets the HTTP Date header.

Parameters
stampA UNIX timestamp, representing the desired time.

Referenced by RemoveHeader().

+ Here is the caller graph for this function:

◆ SetHeader()

void SetHeader ( const std::string &  name,
const std::string &  value 
)
inline

Sets an HTTP header.

Parameters
nameThe name of the HTTP header to set.
valueThe value of the HTTP header to set.
Examples:
ehs_basicauth.cpp, ehs_uploader.cpp, and ehs_wsgate.cpp.

Definition at line 137 of file httpresponse.h.

◆ SetLastModified()

void SetLastModified ( time_t  stamp)

Sets the HTTP Last-Modified header.

Parameters
stampA UNIX timestamp, representing the desired time.

Referenced by RemoveHeader().

+ Here is the caller graph for this function:

◆ SetResponseCode()

void SetResponseCode ( ResponseCode  code)
inline

Sets the response code for this response.

Parameters
codeThe desired HTTP response code.

Definition at line 115 of file httpresponse.h.


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