big svn cleanup
[anytun.git] / src / Sockets / HttpTransaction.cpp
blob8221d1f69945055e51146d087be005da663b86c6
1 /**
2 ** \file HttpTransaction.cpp
3 ** \date 2007-10-05
4 ** \author grymse@alhem.net
5 **/
6 /*
7 Copyright (C) 2007 Anders Hedstrom
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #ifdef _MSC_VER
24 #pragma warning(disable:4786)
25 #endif
26 #include "HttpTransaction.h"
27 #include "Utility.h"
28 #include "Parse.h"
30 #ifdef SOCKETS_NAMESPACE
31 namespace SOCKETS_NAMESPACE {
32 #endif
35 // --------------------------------------------------------------------------------------
36 HttpTransaction::HttpTransaction()
41 // --------------------------------------------------------------------------------------
42 HttpTransaction::~HttpTransaction()
47 // --------------------------------------------------------------------------------------
48 void HttpTransaction::SetHeader(const std::string& key, const std::string& value)
50 m_header[Utility::ToLower(key)] = value;
54 void HttpTransaction::SetHeader(const std::string& key, long value)
56 m_header[Utility::ToLower(key)] = Utility::l2string(value);
60 const std::string& HttpTransaction::Header(const std::string& key) const
62 std::map<std::string, std::string>::const_iterator it;
63 if ((it = m_header.find(Utility::ToLower(key))) != m_header.end())
64 return it -> second;
65 return m_null;
70 // --------------------------------------------------------------------------------------
71 void HttpTransaction::SetAccept(const std::string& value)
73 SetHeader("accept", value);
77 const std::string& HttpTransaction::Accept() const
79 return Header("accept");
84 // --------------------------------------------------------------------------------------
85 void HttpTransaction::SetAcceptCharset(const std::string& value)
87 SetHeader("accept-charset", value);
91 const std::string& HttpTransaction::AcceptCharset() const
93 return Header("accept-charset");
98 // --------------------------------------------------------------------------------------
99 void HttpTransaction::SetAcceptEncoding(const std::string& value)
101 SetHeader("accept-encoding", value);
105 const std::string& HttpTransaction::AcceptEncoding() const
107 return Header("accept-encoding");
112 // --------------------------------------------------------------------------------------
113 void HttpTransaction::SetAcceptLanguage(const std::string& value)
115 SetHeader("accept-language", value);
119 const std::string& HttpTransaction::AcceptLanguage() const
121 return Header("accept-language");
126 // --------------------------------------------------------------------------------------
127 void HttpTransaction::SetConnection(const std::string& value)
129 SetHeader("connection", value);
133 const std::string& HttpTransaction::Connection() const
135 return Header("connection");
140 // --------------------------------------------------------------------------------------
141 void HttpTransaction::SetContentType(const std::string& value)
143 SetHeader("content-type", value);
147 const std::string& HttpTransaction::ContentType() const
149 return Header("content-type");
154 // --------------------------------------------------------------------------------------
155 void HttpTransaction::SetContentLength(long value)
157 SetHeader("content-length", value );
161 long HttpTransaction::ContentLength() const
163 return atol(Header("content-length").c_str());
168 // --------------------------------------------------------------------------------------
169 void HttpTransaction::SetHost(const std::string& value)
171 SetHeader("host", value);
175 const std::string& HttpTransaction::Host() const
177 return Header("host");
182 // --------------------------------------------------------------------------------------
183 void HttpTransaction::SetPragma(const std::string& value)
185 SetHeader("pragma", value);
189 const std::string& HttpTransaction::Pragma() const
191 return Header("pragma");
196 // --------------------------------------------------------------------------------------
197 void HttpTransaction::SetReferer(const std::string& value)
199 SetHeader("referer", value);
203 const std::string& HttpTransaction::Referer() const
205 return Header("referer");
210 // --------------------------------------------------------------------------------------
211 void HttpTransaction::SetUserAgent(const std::string& value)
213 SetHeader("user-agent", value);
217 const std::string& HttpTransaction::UserAgent() const
219 return Header("user-agent");
223 // --------------------------------------------------------------------------------------
224 const std::map<std::string, std::string>& HttpTransaction::Headers() const
226 return m_header;
230 // --------------------------------------------------------------------------------------
231 void HttpTransaction::Reset()
233 while (!m_header.empty())
235 m_header.erase(m_header.begin());
240 #ifdef SOCKETS_NAMESPACE
241 } // namespace SOCKETS_NAMESPACE {
242 #endif