2013-09-27 18:14:26 +02:00
|
|
|
|
|
|
|
|
// HTTPMessage.h
|
|
|
|
|
|
|
|
|
|
// Declares the cHTTPMessage class representing the common ancestor for HTTP request and response classes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2013-10-04 13:07:57 +02:00
|
|
|
#include "EnvelopeParser.h"
|
|
|
|
|
|
2013-09-27 18:14:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cHTTPMessage
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-08-02 22:56:08 -07:00
|
|
|
enum eStatus
|
2013-09-27 18:14:26 +02:00
|
|
|
{
|
|
|
|
|
HTTP_OK = 200,
|
|
|
|
|
HTTP_BAD_REQUEST = 400,
|
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
enum eKind
|
|
|
|
|
{
|
|
|
|
|
mkRequest,
|
|
|
|
|
mkResponse,
|
|
|
|
|
} ;
|
2016-02-05 23:45:45 +02:00
|
|
|
|
2013-09-27 18:14:26 +02:00
|
|
|
cHTTPMessage(eKind a_Kind);
|
|
|
|
|
|
2013-12-20 16:20:54 +01:00
|
|
|
// Force a virtual destructor in all descendants
|
2014-07-22 15:36:13 -07:00
|
|
|
virtual ~cHTTPMessage() {}
|
2016-02-05 23:45:45 +02:00
|
|
|
|
2014-01-18 20:20:56 +01:00
|
|
|
/** Adds a header into the internal map of headers. Recognizes special headers: Content-Type and Content-Length */
|
2013-09-27 18:14:26 +02:00
|
|
|
void AddHeader(const AString & a_Key, const AString & a_Value);
|
2016-02-05 23:45:45 +02:00
|
|
|
|
2013-09-27 18:14:26 +02:00
|
|
|
void SetContentType (const AString & a_ContentType) { m_ContentType = a_ContentType; }
|
2014-04-02 06:36:25 -07:00
|
|
|
void SetContentLength(size_t a_ContentLength) { m_ContentLength = a_ContentLength; }
|
2016-02-05 23:45:45 +02:00
|
|
|
|
2013-09-27 18:14:26 +02:00
|
|
|
const AString & GetContentType (void) const { return m_ContentType; }
|
2014-04-01 16:36:00 +02:00
|
|
|
size_t GetContentLength(void) const { return m_ContentLength; }
|
2013-09-27 18:14:26 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
typedef std::map<AString, AString> cNameValueMap;
|
2016-02-05 23:45:45 +02:00
|
|
|
|
2013-09-27 18:14:26 +02:00
|
|
|
eKind m_Kind;
|
2016-02-05 23:45:45 +02:00
|
|
|
|
2016-01-01 16:42:22 +01:00
|
|
|
/** Map of headers, with their keys lowercased. */
|
2015-12-25 19:54:04 +01:00
|
|
|
AStringMap m_Headers;
|
2013-09-27 18:14:26 +02:00
|
|
|
|
2014-01-18 20:20:56 +01:00
|
|
|
/** Type of the content; parsed by AddHeader(), set directly by SetContentLength() */
|
2013-09-27 18:14:26 +02:00
|
|
|
AString m_ContentType;
|
|
|
|
|
|
2014-04-01 16:36:00 +02:00
|
|
|
/** Length of the content that is to be received.
|
|
|
|
|
AString::npos when the object is created.
|
|
|
|
|
Parsed by AddHeader() or set directly by SetContentLength() */
|
|
|
|
|
size_t m_ContentLength;
|
2013-09-27 18:14:26 +02:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cHTTPResponse :
|
|
|
|
|
public cHTTPMessage
|
|
|
|
|
{
|
|
|
|
|
typedef cHTTPMessage super;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
cHTTPResponse(void);
|
2016-02-05 23:45:45 +02:00
|
|
|
|
2013-09-27 18:14:26 +02:00
|
|
|
/** Appends the response to the specified datastream - response line and headers.
|
|
|
|
|
The body will be sent later directly through cConnection::Send()
|
|
|
|
|
*/
|
|
|
|
|
void AppendToData(AString & a_DataStream) const;
|
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|