00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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