• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/web/HttpResponse.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _httpresponse_h
00018 #define _httpresponse_h
00019 
00020 #include <spl/Debug.h>
00021 #include <spl/collection/Array.h>
00022 #include <spl/web/HttpHeader.h>
00023 #include <spl/Memory.h>
00024 #include <spl/io/Stream.h>
00025 #include <spl/io/MemoryStream.h>
00026 #include <spl/String.h>
00027 #include <spl/text/StringBuffer.h>
00028 #include <spl/io/TextStream.h>
00029 
00035 class HttpResponse : public IMemoryValidate
00036 {
00037 private:
00038         enum State
00039         {
00040                 HTTPRES_STATE_VERSION = 0,
00041                 HTTPRES_STATE_CODE = 1,
00042                 HTTPRES_STATE_MESSAGE = 2,
00043                 HTTPRES_STATE_HEADERS = 3,
00044                 HTTPRES_STATE_BODY = 4
00045         };
00046 
00047 protected:
00048         String m_httpVersion;
00049         int m_statusCode;
00050         HttpHeader m_header;
00051         MemoryStreamPtr m_body;
00052 
00053         StringBuffer m_accum;
00054         enum HttpResponse::State m_state;
00055 
00056 public:
00057         HttpResponse();
00058         HttpResponse(const HttpResponse& resp);
00059         virtual ~HttpResponse();
00060 
00061         HttpResponse& operator =(const HttpResponse& resp);
00062 
00063         inline int& StatusCode() { return m_statusCode; }
00064         
00065         inline void AddHeader(const String& header, const String& value) { m_header.Header(header) = value; }
00066         inline HttpHeader& Headers() { return m_header; }
00067 
00068         inline spl::IStreamPtr GetBodyStream() { return m_body; }
00069 
00070         inline int ContentLength() { return m_body->Length(); }
00071 
00072         void Write( spl::IStream& strm );
00073 
00074         void Parse( const Array<byte>& data, int len );
00075         void Parse( spl::IStream& strm );
00076 
00077         static String GetResponseText(int responseCode);
00078 
00079 #ifdef DEBUG
00080         virtual void ValidateMem() const;
00081         virtual void CheckMem() const;
00082 #endif
00083 };
00084 
00087 #endif