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

spl/web/HttpRequest.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 _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;   // HTTP/1.0
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