00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef _MSC_VER
00034 #pragma warning(disable:4786)
00035 #endif
00036 #include "HttpTransaction.h"
00037
00038 #ifdef SOCKETS_NAMESPACE
00039 namespace SOCKETS_NAMESPACE {
00040 #endif
00041
00042
00043
00044 HttpTransaction::HttpTransaction()
00045 {
00046 }
00047
00048
00049
00050 HttpTransaction::~HttpTransaction()
00051 {
00052 }
00053
00054
00055
00056 void HttpTransaction::SetHeader(const std::string& key, const std::string& value)
00057 {
00058 m_header[key] = value;
00059 }
00060
00061
00062 void HttpTransaction::SetHeader(const std::string& key, long value)
00063 {
00064 m_header[key] = Utility::l2string(value);
00065 }
00066
00067
00068 const std::string& HttpTransaction::Header(const std::string& key) const
00069 {
00070 Utility::ncmap<std::string>::const_iterator it;
00071 if ((it = m_header.find(key)) != m_header.end())
00072 return it -> second;
00073 return m_null;
00074 }
00075
00076
00077
00078
00079 void HttpTransaction::SetAccept(const std::string& value)
00080 {
00081 SetHeader("accept", value);
00082 }
00083
00084
00085 const std::string& HttpTransaction::Accept() const
00086 {
00087 return Header("accept");
00088 }
00089
00090
00091
00092
00093 void HttpTransaction::SetAcceptCharset(const std::string& value)
00094 {
00095 SetHeader("accept-charset", value);
00096 }
00097
00098
00099 const std::string& HttpTransaction::AcceptCharset() const
00100 {
00101 return Header("accept-charset");
00102 }
00103
00104
00105
00106
00107 void HttpTransaction::SetAcceptEncoding(const std::string& value)
00108 {
00109 SetHeader("accept-encoding", value);
00110 }
00111
00112
00113 const std::string& HttpTransaction::AcceptEncoding() const
00114 {
00115 return Header("accept-encoding");
00116 }
00117
00118
00119
00120
00121 void HttpTransaction::SetAcceptLanguage(const std::string& value)
00122 {
00123 SetHeader("accept-language", value);
00124 }
00125
00126
00127 const std::string& HttpTransaction::AcceptLanguage() const
00128 {
00129 return Header("accept-language");
00130 }
00131
00132
00133
00134
00135 void HttpTransaction::SetConnection(const std::string& value)
00136 {
00137 SetHeader("connection", value);
00138 }
00139
00140
00141 const std::string& HttpTransaction::Connection() const
00142 {
00143 return Header("connection");
00144 }
00145
00146
00147
00148
00149 void HttpTransaction::SetContentType(const std::string& value)
00150 {
00151 SetHeader("content-type", value);
00152 }
00153
00154
00155 const std::string& HttpTransaction::ContentType() const
00156 {
00157 return Header("content-type");
00158 }
00159
00160
00161
00162
00163 void HttpTransaction::SetContentLength(long value)
00164 {
00165 SetHeader("content-length", value );
00166 }
00167
00168
00169 long HttpTransaction::ContentLength() const
00170 {
00171 return atol(Header("content-length").c_str());
00172 }
00173
00174
00175
00176
00177 void HttpTransaction::SetHost(const std::string& value)
00178 {
00179 SetHeader("host", value);
00180 }
00181
00182
00183 const std::string& HttpTransaction::Host() const
00184 {
00185 return Header("host");
00186 }
00187
00188
00189 const std::string HttpTransaction::HostOnly() const
00190 {
00191 std::string host = Header("host");
00192 size_t pos = host.find(":");
00193 if (pos != std::string::npos)
00194 return host.substr(0, pos);
00195 return host;
00196 }
00197
00198
00199
00200
00201 void HttpTransaction::SetPragma(const std::string& value)
00202 {
00203 SetHeader("pragma", value);
00204 }
00205
00206
00207 const std::string& HttpTransaction::Pragma() const
00208 {
00209 return Header("pragma");
00210 }
00211
00212
00213
00214
00215 void HttpTransaction::SetReferer(const std::string& value)
00216 {
00217 SetHeader("referer", value);
00218 }
00219
00220
00221 const std::string& HttpTransaction::Referer() const
00222 {
00223 return Header("referer");
00224 }
00225
00226
00227
00228
00229 void HttpTransaction::SetUserAgent(const std::string& value)
00230 {
00231 SetHeader("user-agent", value);
00232 }
00233
00234
00235 const std::string& HttpTransaction::UserAgent() const
00236 {
00237 return Header("user-agent");
00238 }
00239
00240
00241
00242 const Utility::ncmap<std::string>& HttpTransaction::Headers() const
00243 {
00244 return m_header;
00245 }
00246
00247
00248
00249 void HttpTransaction::Reset()
00250 {
00251 while (!m_header.empty())
00252 {
00253 m_header.erase(m_header.begin());
00254 }
00255 }
00256
00257
00258 #ifdef SOCKETS_NAMESPACE
00259 }
00260 #endif
00261
00262