Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/tntnet/framework/common/tnt/httpmessage.h

00001 /*
00002  * Copyright (C) 2003-2005 Tommi Maekitalo
00003  * 
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  * 
00009  * As a special exception, you may use this file as part of a free
00010  * software library without restriction. Specifically, if other files
00011  * instantiate templates or use macros or inline functions from this
00012  * file, or you compile this file and link it with other files to
00013  * produce an executable, this file does not by itself cause the
00014  * resulting executable to be covered by the GNU General Public
00015  * License. This exception does not however invalidate any other
00016  * reasons why the executable file might be covered by the GNU Library
00017  * General Public License.
00018  * 
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this library; if not, write to the Free Software
00026  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00027  */
00028 
00029 
00030 #ifndef TNT_HTTPMESSAGE_H
00031 #define TNT_HTTPMESSAGE_H
00032 
00033 #include <tnt/messageheader.h>
00034 #include <tnt/httpheader.h>
00035 #include <tnt/cookie.h>
00036 #include <time.h>
00037 
00038 namespace tnt
00039 {
00041   class HttpMessage
00042   {
00043     public:
00044       typedef Messageheader header_type;
00045 
00046     private:
00047       unsigned short majorVersion;
00048       unsigned short minorVersion;
00049 
00050     protected:
00051       header_type header;
00052       Cookies httpcookies;
00053 
00054     public:
00055       HttpMessage()
00056         : majorVersion(1),
00057           minorVersion(0)
00058         { }
00059       virtual ~HttpMessage()
00060       { }
00061 
00063       virtual void clear();
00064 
00066       bool hasHeader(const char* key) const        { return header.hasHeader(key); }
00067       bool hasHeader(const std::string& key) const { return header.hasHeader(key); }
00070       const char* getHeader(const char* key, const char* def = "") const;
00071 
00073       unsigned short getMajorVersion() const
00074         { return majorVersion; }
00076       unsigned short getMinorVersion() const
00077         { return minorVersion; }
00079       void setVersion(unsigned short major, unsigned short minor)
00080         { majorVersion = major; minorVersion = minor; }
00081 
00084       header_type::const_iterator header_begin() const
00085         { return header.begin(); }
00087       header_type::const_iterator header_end() const
00088         { return header.end(); }
00089 
00091       void setHeader(const std::string& key, const std::string& value, bool replace = true)
00092         { header.setHeader(key, value, replace); }
00094       void removeHeader(const std::string& key)
00095         { header.removeHeader(key); }
00096 
00098       std::string dumpHeader() const;
00100       void dumpHeader(std::ostream& out) const;
00101 
00103       static std::string htdate(time_t t);
00105       static std::string htdate(struct ::tm* tm);
00107       static std::string htdateCurrent();
00108 
00111       static bool checkUrl(const std::string& url);
00112   };
00113 }
00114 
00115 #endif // TNT_HTTPMESSAGE_H
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6