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

spl/web/HttpHeader.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 _httpheader_h
00018 #define _httpheader_h
00019 
00020 #include <spl/Debug.h>
00021 #include <spl/collection/Association.h>
00022 #include <spl/collection/Hashtable.h>
00023 #include <spl/io/IStream.h>
00024 #include <spl/Memory.h>
00025 #include <spl/String.h>
00026 #include <spl/collection/Vector.h>
00027 
00033 class HttpHeader : public IMemoryValidate
00034 {
00035 protected:
00036         Vector<Association<String, String> > m_headers;
00037         Hashtable<String, int> m_headerIdx;
00038 
00039 public:
00040         inline HttpHeader(const HttpHeader& hdr)
00041         : m_headers(hdr.m_headers), m_headerIdx(hdr.m_headerIdx)
00042         {
00043         }
00044 
00045         HttpHeader();
00046         virtual ~HttpHeader();
00047 
00048         inline HttpHeader& operator =(const HttpHeader& hdr)
00049         {
00050                 m_headers = hdr.m_headers;
00051                 m_headerIdx = hdr.m_headerIdx;
00052                 return *this;
00053         }
00054 
00055         String& Header(const String& name);
00056 
00057         inline bool HasHeader(const String& name) const 
00058         { 
00059                 return m_headerIdx.ContainsKey(name); 
00060         }
00061 
00062         inline String& ContentLength()
00063         { 
00064                 return Header("Content-Length"); 
00065         }
00066 
00067         inline String& ContentType()
00068         { 
00069                 return Header("Content-Type"); 
00070         }
00071 
00072         inline int Count() const 
00073         { 
00074                 return m_headers.Count(); 
00075         }
00076 
00077         void ParseLine( const String& line );
00078 
00079         void Write(spl::IStream& stream) const;
00080         StringPtr ToString() const;
00081 
00082 #ifdef DEBUG
00083         virtual void ValidateMem() const;
00084         virtual void CheckMem() const;
00085 #endif
00086 };
00087 
00090 #endif