EHS Embedded HTTP Server  1.5.0.132
httpresponse.h
00001 /* $Id: httpresponse.h 127 2012-04-07 06:08:05Z felfert $
00002  *
00003  * EHS is a library for embedding HTTP(S) support into a C++ application
00004  *
00005  * Copyright (C) 2004 Zachary J. Hansen
00006  *
00007  * Code cleanup, new features and bugfixes: Copyright (C) 2010 Fritz Elfert
00008  *
00009  *    This library is free software; you can redistribute it and/or
00010  *    modify it under the terms of the GNU Lesser General Public
00011  *    License version 2.1 as published by the Free Software Foundation;
00012  *
00013  *    This library is distributed in the hope that it will be useful,
00014  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *    Lesser General Public License for more details.
00017  *
00018  *    You should have received a copy of the GNU Lesser General Public
00019  *    License along with this library; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  *    This can be found in the 'COPYING' file.
00023  *
00024  */
00025 
00026 #ifndef HTTPRESPONSE_H
00027 #define HTTPRESPONSE_H
00028 
00029 #include <ehstypes.h>
00030 
00032 enum ResponseCode {
00033     HTTPRESPONSECODE_INVALID = 0,
00034     HTTPRESPONSECODE_101_SWITCHING_PROTOCOLS = 101,
00035     HTTPRESPONSECODE_200_OK = 200,
00036     HTTPRESPONSECODE_301_MOVEDPERMANENTLY = 301,
00037     HTTPRESPONSECODE_302_FOUND = 302,
00038     HTTPRESPONSECODE_304_NOT_MODIFIED = 304,
00039     HTTPRESPONSECODE_400_BADREQUEST = 400,
00040     HTTPRESPONSECODE_401_UNAUTHORIZED = 401,
00041     HTTPRESPONSECODE_403_FORBIDDEN = 403,
00042     HTTPRESPONSECODE_404_NOTFOUND = 404,
00043     HTTPRESPONSECODE_413_TOOLARGE = 413,
00044     HTTPRESPONSECODE_426_UPGRADE_REQUIRED = 426,
00045     HTTPRESPONSECODE_500_INTERNALSERVERERROR = 500,
00046     HTTPRESPONSECODE_503_SERVICEUNAVAILABLE = 503
00047 };
00048 
00054 class HttpResponse : public GenericResponse {
00055 
00056     private:
00057         HttpResponse( const HttpResponse & );
00058         HttpResponse &operator = (const HttpResponse &);
00059 
00060     public:
00066         HttpResponse(int inResponseId, EHSConnection * ipoEHSConnection);
00067 
00075         static HttpResponse *Error(ResponseCode code, int inResponseId, EHSConnection * ipoEHSConnection);
00076 
00084         static HttpResponse *Error(ResponseCode code, HttpRequest *request);
00085 
00092         static const char *GetPhrase(ResponseCode code);
00093 
00095         virtual ~HttpResponse ( ) { }
00096 
00103         void SetBody(const char *ipsBody, size_t inBodyLength);
00104 
00109         void SetCookie(CookieParameters & iroCookieParameters);
00110 
00115         void SetResponseCode(ResponseCode code) { m_nResponseCode = code; }
00116 
00120         ResponseCode GetResponseCode() { return m_nResponseCode; }
00121 
00125         StringCaseMap& GetHeaders() { return m_oResponseHeaders; }
00126 
00130         StringList& GetCookies() { return m_oCookieList; }
00131 
00137         void SetHeader(const std::string & name, const std::string & value)
00138         {
00139             m_oResponseHeaders[name] = value;
00140         }
00141 
00146         void RemoveHeader(const std::string & name)
00147         {
00148             m_oResponseHeaders.erase(name);
00149         }
00150 
00155         std::string GetStatusString();
00156 
00161         void SetDate(time_t stamp);
00162 
00167         void SetLastModified(time_t stamp);
00168 
00175         std::string HttpTime(time_t stamp);
00176 
00177     private:
00178 
00180         ResponseCode m_nResponseCode;
00181 
00184         StringCaseMap m_oResponseHeaders;
00185 
00187         StringList m_oCookieList;
00188 };
00189 
00190 #endif // HTTPRESPONSE_H