GClasses
GClasses::GHttpConnection Class Referenceabstract

Detailed Description

Each GHttpConnection represents an HTTP connection between a client and the server. A GHTTPServer is a collection of GHTTPConnection objects. To implement a HTTP server, you will typically override the doGet and doPost methods of this class to generate web pages.

#include <GHttp.h>

Inheritance diagram for GClasses::GHttpConnection:
GClasses::GTCPConnection GClasses::GDynamicPageConnection

Public Types

Public Member Functions

 GHttpConnection (SOCKET sock)
 General-purpose constructor. More...
 
virtual ~GHttpConnection ()
 
virtual void doGet (std::ostream &response)=0
 The primary purpose of this method is to push a response into pResponse. Typically this method will call SetHeaders. More...
 
virtual void doPost (std::ostream &response)=0
 This method takes ownership of pData. Don't forget to delete it. When the POST is caused by an HTML form, it's common for this method to just call DoGet (passing pData for szParams) and then delete pData. (For convenience, a '\0' is already appended at the end of pData.) More...
 
virtual bool hasBeenModifiedSince (const char *szUrl, const char *szDate)=0
 This is called when the client does a conditional GET. It should return true if you wish to re-send the file, and DoGet will be called. More...
 
void reset ()
 Clear all the buffers in this object. More...
 
void setContentType (const char *szContentType)
 Specify the type of the content that is being sent to the client. More...
 
void setCookie (const char *szPayload, bool bPersist)
 Specify a cookie to send to the client with this response. More...
 
virtual void setHeaders (const char *szUrl, const char *szParams)=0
 This method should set the content type and the date headers, and any other headers deemed necessary. More...
 
void setModifiedTime (time_t t)
 Sets the date (modified time) to be sent with the file so the client can cache it. More...
 
- Public Member Functions inherited from GClasses::GTCPConnection
 GTCPConnection (SOCKET sock)
 
virtual ~GTCPConnection ()
 
in_addr ipAddr ()
 Returns the client's IP address for this connection. (You can use inet_ntoa to convert the value this returns to a string.) More...
 
void setSocket (SOCKET sock)
 Sets the socket for this connection. More...
 
SOCKET socket ()
 Returns the socket associated with this connection. More...
 

Public Attributes

bool m_bPersistCookie
 
RequestType m_eRequestType
 
time_t m_modifiedTime
 
size_t m_nContentLength
 
size_t m_nPos
 
char * m_pContent
 
char * m_pPostBuffer
 
char m_szContentType [MAX_MIME_LEN]
 
char m_szCookieIncoming [MAX_COOKIE_SIZE]
 
char m_szCookieOutgoing [MAX_COOKIE_SIZE]
 
char m_szDate [MAX_DATE_LEN]
 
char m_szLine [MAX_HEADER_LEN]
 
char m_szParams [MAX_URL_LEN]
 
char m_szUrl [MAX_URL_LEN]
 

Additional Inherited Members

- Protected Attributes inherited from GClasses::GTCPConnection
SOCKET m_sock
 

Member Enumeration Documentation

Enumerator
None 
Get 
Head 
Post 

Constructor & Destructor Documentation

GClasses::GHttpConnection::GHttpConnection ( SOCKET  sock)

General-purpose constructor.

virtual GClasses::GHttpConnection::~GHttpConnection ( )
virtual

Member Function Documentation

virtual void GClasses::GHttpConnection::doGet ( std::ostream &  response)
pure virtual

The primary purpose of this method is to push a response into pResponse. Typically this method will call SetHeaders.

Implemented in GClasses::GDynamicPageConnection.

virtual void GClasses::GHttpConnection::doPost ( std::ostream &  response)
pure virtual

This method takes ownership of pData. Don't forget to delete it. When the POST is caused by an HTML form, it's common for this method to just call DoGet (passing pData for szParams) and then delete pData. (For convenience, a '\0' is already appended at the end of pData.)

Implemented in GClasses::GDynamicPageConnection.

virtual bool GClasses::GHttpConnection::hasBeenModifiedSince ( const char *  szUrl,
const char *  szDate 
)
pure virtual

This is called when the client does a conditional GET. It should return true if you wish to re-send the file, and DoGet will be called.

Implemented in GClasses::GDynamicPageConnection.

void GClasses::GHttpConnection::reset ( )

Clear all the buffers in this object.

void GClasses::GHttpConnection::setContentType ( const char *  szContentType)

Specify the type of the content that is being sent to the client.

void GClasses::GHttpConnection::setCookie ( const char *  szPayload,
bool  bPersist 
)

Specify a cookie to send to the client with this response.

virtual void GClasses::GHttpConnection::setHeaders ( const char *  szUrl,
const char *  szParams 
)
pure virtual

This method should set the content type and the date headers, and any other headers deemed necessary.

Implemented in GClasses::GDynamicPageConnection.

void GClasses::GHttpConnection::setModifiedTime ( time_t  t)
inline

Sets the date (modified time) to be sent with the file so the client can cache it.

Member Data Documentation

bool GClasses::GHttpConnection::m_bPersistCookie
RequestType GClasses::GHttpConnection::m_eRequestType
time_t GClasses::GHttpConnection::m_modifiedTime
size_t GClasses::GHttpConnection::m_nContentLength
size_t GClasses::GHttpConnection::m_nPos
char* GClasses::GHttpConnection::m_pContent
char* GClasses::GHttpConnection::m_pPostBuffer
char GClasses::GHttpConnection::m_szContentType[MAX_MIME_LEN]
char GClasses::GHttpConnection::m_szCookieIncoming[MAX_COOKIE_SIZE]
char GClasses::GHttpConnection::m_szCookieOutgoing[MAX_COOKIE_SIZE]
char GClasses::GHttpConnection::m_szDate[MAX_DATE_LEN]
char GClasses::GHttpConnection::m_szLine[MAX_HEADER_LEN]
char GClasses::GHttpConnection::m_szParams[MAX_URL_LEN]
char GClasses::GHttpConnection::m_szUrl[MAX_URL_LEN]