00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _httprequest_h
00018 #define _httprequest_h
00019
00020 #include <spl/collection/Array.h>
00021 #include <spl/web/HttpRequestBody.h>
00022 #include <spl/web/HttpHeader.h>
00023 #include <spl/web/HttpResponse.h>
00024 #include <spl/Memory.h>
00025 #include <spl/text/StringBuffer.h>
00026 #include <spl/web/Uri.h>
00027
00033 class HttpRequest : public IMemoryValidate
00034 {
00035 private:
00036 enum State
00037 {
00038 HTTPREQ_STATE_METHOD = 0,
00039 HTTPREQ_STATE_URI = 1,
00040 HTTPREQ_STATE_VERSION = 2,
00041 HTTPREQ_STATE_HEADERS = 3,
00042 HTTPREQ_STATE_BODY = 4
00043 };
00044
00045 protected:
00046 String m_method;
00047 Uri m_uri;
00048 String m_httpVersion;
00049 HttpHeader m_header;
00050 IHttpRequestBody *m_body;
00051
00052 HttpRequest::State m_state;
00053 StringBuffer m_accum;
00054
00055 bool ParseLine(const byte *data, int len, int *pos);
00056
00057 public:
00058 HttpRequest();
00059 HttpRequest(const String& uri);
00060 HttpRequest(const HttpRequest& req);
00061 virtual ~HttpRequest();
00062
00063 HttpRequest& operator =(const HttpRequest& req);
00064
00065 inline String& Method() { return m_method; }
00066 inline Uri& URI() { return m_uri; }
00067
00068 void Parse(const Array<byte>& data, int len);
00069 bool IsComplete();
00070
00071 HttpResponse *Send();
00072
00073 inline HttpHeader& Headers() { return m_header; }
00074
00075 StringPtr ToString() const;
00076
00077 #ifdef DEBUG
00078 virtual void ValidateMem() const;
00079 virtual void CheckMem() const;
00080 #endif
00081 };
00082
00085 #endif