![]() |
HTTPSocket Class ReferenceHTTP request/response base class.
More...
|
Public Member Functions | |
HTTPSocket (ISocketHandler &) | |
~HTTPSocket () | |
void | OnRawData (const char *buf, size_t len) |
This callback is executed after a successful read from the socket. | |
void | OnLine (const std::string &line) |
Callback fires when a socket in line protocol has read one full line. | |
virtual void | OnFirst ()=0 |
Callback executes when first line has been received. | |
virtual void | OnHeader (const std::string &key, const std::string &value)=0 |
For each header line this callback is executed. | |
virtual void | OnHeaderComplete ()=0 |
Callback fires when all http headers have been received. | |
virtual void | OnData (const char *, size_t)=0 |
Chunk of http body data recevied. | |
virtual void | OnDataComplete () |
The full request/response body has been received. | |
const std::string & | GetMethod () const |
Get http method from incoming request, ie GET/POST/PUT etc. | |
const std::string & | GetUrl () const |
Get url from request. | |
const std::string & | GetUri () const |
Get part of url before '?' character. | |
const std::string & | GetQueryString () const |
Get part of url after '?' character. | |
const std::string & | GetHttpVersion () const |
Get http version from incoming request/response. | |
const std::string & | GetStatus () const |
Get http status from incoming response. | |
const std::string & | GetStatusText () const |
Get http statustext from incoming response. | |
bool | IsRequest () const |
Incoming header has been identified as a request (method url http_version ). | |
bool | IsResponse () const |
Incoming header has been identified as a response (http_version status status_text ). | |
void | SetHttpVersion (const std::string &x) |
Set http version to be used in outgoing request/response. | |
void | SetStatus (const std::string &x) |
Set http status for outgoing response. | |
void | SetStatusText (const std::string &x) |
Set http statustext for outgoing response. | |
void | AddResponseHeader (const std::string &x, const std::string &y) |
Add (and replace if exists) http header. | |
void | AddResponseHeader (const std::string &x, const char *format,...) |
Add (and replace if exists) http header. | |
void | AppendResponseHeader (const std::string &x, const std::string &y) |
Add http header. | |
bool | ResponseHeaderIsSet (const std::string &name) const |
See if http header 'name' has been set. | |
void | SendResponse () |
Send response prepared with calls to methods SetHttpVersion, SetStatus, SetStatusText, and AddResponseHeader. | |
void | SendRequest () |
Send request prepared with calls to methods SetMethod, SetUrl, SetHttpVersion, and AddResponseHeader. | |
virtual std::string | MyUseragent () |
Implement this to return your own User-agent string. | |
void | url_this (const std::string &url_in, std::string &protocol, std::string &host, port_t &port, std::string &url, std::string &file) |
Parse url. | |
bool | IsChunked () const |
Transfer coding 'chunked'. | |
Protected Member Functions | |
HTTPSocket (const HTTPSocket &s) | |
virtual void | Reset () |
Reset state of socket to sucessfully implement keep-alive. | |
void | SetMaxHeaderCount (int x) |
void | SetMethod (const std::string &x) |
Set http method to be used in request. | |
void | SetUrl (const std::string &x) |
Set url to be used in outgoing request. | |
void | SetUri (const std::string &x) |
Now why would I need this when there is a SetUrl method? | |
Private Types | |
typedef Utility::ncmap < std::string > | string_m |
map to hold http header values. | |
Private Member Functions | |
HTTPSocket & | operator= (const HTTPSocket &) |
Private Attributes | |
bool | m_first |
bool | m_header |
std::string | m_line |
Current line in line protocol mode. | |
std::string | m_method |
std::string | m_url |
std::string | m_uri |
std::string | m_query_string |
std::string | m_http_version |
std::string | m_status |
std::string | m_status_text |
bool | m_request |
bool | m_response |
string_m | m_response_header |
size_t | m_body_size_left |
bool | m_b_http_1_1 |
bool | m_b_keepalive |
std::list< std::pair < std::string, std::string > > | m_response_header_append |
bool | m_b_chunked |
size_t | m_chunk_size |
int | m_chunk_state |
std::string | m_chunk_line |
int | m_header_count |
int | m_max_header_count |
Definition at line 47 of file HTTPSocket.h.
typedef Utility::ncmap<std::string> HTTPSocket::string_m [private] |
HTTPSocket::HTTPSocket | ( | ISocketHandler & | h | ) |
Definition at line 46 of file HTTPSocket.cpp.
References TcpSocket::DisableInputBuffer(), and TcpSocket::SetLineProtocol().
00047 :TcpSocket(h) 00048 ,m_first(true) 00049 ,m_header(true) 00050 ,m_http_version("HTTP/1.0") 00051 ,m_request(false) 00052 ,m_response(false) 00053 ,m_body_size_left(0) 00054 ,m_b_http_1_1(false) 00055 ,m_b_keepalive(false) 00056 ,m_b_chunked(false) 00057 ,m_chunk_size(0) 00058 ,m_chunk_state(0) 00059 ,m_header_count(0) 00060 ,m_max_header_count(MAX_HTTP_HEADER_COUNT) 00061 { 00062 SetLineProtocol(); 00063 DisableInputBuffer(); 00064 }
HTTPSocket::~HTTPSocket | ( | ) |
HTTPSocket::HTTPSocket | ( | const HTTPSocket & | s | ) | [inline, protected] |
void HTTPSocket::OnRawData | ( | const char * | buf, | |
size_t | len | |||
) | [virtual] |
This callback is executed after a successful read from the socket.
buf | Pointer to the data | |
len | Length of the data |
Reimplemented from TcpSocket.
Definition at line 72 of file HTTPSocket.cpp.
References Parse::getword(), Utility::hex2unsigned(), m_b_chunked, m_b_http_1_1, m_b_keepalive, m_body_size_left, m_chunk_line, m_chunk_size, m_chunk_state, m_first, m_header, OnData(), OnDataComplete(), TcpSocket::OnRead(), TcpSocket::SetLineProtocol(), and TCP_BUFSIZE_READ.
00073 { 00074 if (!m_header) 00075 { 00076 if (m_b_chunked) 00077 { 00078 size_t ptr = 0; 00079 while (ptr < len) 00080 { 00081 switch (m_chunk_state) 00082 { 00083 case 4: 00084 while (ptr < len && (m_chunk_line.size() < 2 || m_chunk_line.substr(m_chunk_line.size() - 2) != "\r\n")) 00085 m_chunk_line += buf[ptr++]; 00086 if (m_chunk_line.size() > 1 && m_chunk_line.substr(m_chunk_line.size() - 2) == "\r\n") 00087 { 00088 OnDataComplete(); 00089 // prepare for next request(or response) 00090 m_b_chunked = false; 00091 SetLineProtocol( true ); 00092 m_first = true; 00093 m_header = true; 00094 m_body_size_left = 0; 00095 if (len - ptr > 0) 00096 { 00097 char tmp[TCP_BUFSIZE_READ]; 00098 memcpy(tmp, buf + ptr, len - ptr); 00099 tmp[len - ptr] = 0; 00100 OnRead( tmp, len - ptr ); 00101 ptr = len; 00102 } 00103 } 00104 break; 00105 case 0: 00106 while (ptr < len && (m_chunk_line.size() < 2 || m_chunk_line.substr(m_chunk_line.size() - 2) != "\r\n")) 00107 m_chunk_line += buf[ptr++]; 00108 if (m_chunk_line.size() > 1 && m_chunk_line.substr(m_chunk_line.size() - 2) == "\r\n") 00109 { 00110 m_chunk_line.resize(m_chunk_line.size() - 2); 00111 Parse pa(m_chunk_line, ";"); 00112 std::string size_str = pa.getword(); 00113 m_chunk_size = Utility::hex2unsigned(size_str); 00114 if (!m_chunk_size) 00115 { 00116 m_chunk_state = 4; 00117 m_chunk_line = ""; 00118 } 00119 else 00120 { 00121 m_chunk_state = 1; 00122 m_chunk_line = ""; 00123 } 00124 } 00125 break; 00126 case 1: 00127 { 00128 size_t left = len - ptr; 00129 size_t sz = m_chunk_size < left ? m_chunk_size : left; 00130 OnData(buf + ptr, sz); 00131 m_chunk_size -= sz; 00132 ptr += sz; 00133 if (!m_chunk_size) 00134 { 00135 m_chunk_state = 2; 00136 } 00137 } 00138 break; 00139 case 2: // skip CR 00140 ptr++; 00141 m_chunk_state = 3; 00142 break; 00143 case 3: // skip LF 00144 ptr++; 00145 m_chunk_state = 0; 00146 break; 00147 } 00148 } 00149 } 00150 else 00151 if (!m_b_http_1_1 || !m_b_keepalive) 00152 { 00153 OnData(buf, len); 00154 /* 00155 request is HTTP/1.0 _or_ HTTP/1.1 and not keep-alive 00156 00157 This means we destroy the connection after the response has been delivered, 00158 hence no need to reset all internal state variables for a new incoming 00159 request. 00160 */ 00161 m_body_size_left -= len; 00162 if (!m_body_size_left) 00163 { 00164 OnDataComplete(); 00165 } 00166 } 00167 else 00168 { 00169 size_t sz = m_body_size_left < len ? m_body_size_left : len; 00170 OnData(buf, sz); 00171 m_body_size_left -= sz; 00172 if (!m_body_size_left) 00173 { 00174 OnDataComplete(); 00175 // prepare for next request(or response) 00176 SetLineProtocol( true ); 00177 m_first = true; 00178 m_header = true; 00179 m_body_size_left = 0; 00180 if (len - sz > 0) 00181 { 00182 char tmp[TCP_BUFSIZE_READ]; 00183 memcpy(tmp, buf + sz, len - sz); 00184 tmp[len - sz] = 0; 00185 OnRead( tmp, len - sz ); 00186 } 00187 } 00188 } 00189 } 00190 }
void HTTPSocket::OnLine | ( | const std::string & | line | ) | [virtual] |
Callback fires when a socket in line protocol has read one full line.
line | Line read |
Reimplemented from TcpSocket.
Definition at line 193 of file HTTPSocket.cpp.
References Parse::getrest(), Parse::getword(), Socket::Handler(), Utility::l2string(), LOG_LEVEL_FATAL, ISocketHandler::LogError(), m_b_chunked, m_b_http_1_1, m_b_keepalive, m_body_size_left, m_first, m_header, m_header_count, m_http_version, m_max_header_count, m_method, m_query_string, m_request, m_response, m_status, m_status_text, m_uri, m_url, OnDataComplete(), OnFirst(), OnHeader(), OnHeaderComplete(), Socket::SetCloseAndDelete(), TcpSocket::SetLineProtocol(), Socket::SetRetain(), and Utility::ToLower().
00194 { 00195 if (m_first) 00196 { 00197 Parse pa(line); 00198 std::string str = pa.getword(); 00199 if (str.size() > 4 && Utility::ToLower(str.substr(0,5)) == "http/") // response 00200 { 00201 m_http_version = str; 00202 m_status = pa.getword(); 00203 m_status_text = pa.getrest(); 00204 m_response = true; 00205 } 00206 else // request 00207 { 00208 m_method = str; 00209 m_url = pa.getword(); 00210 size_t spl = m_url.find("?"); 00211 if (spl != std::string::npos) 00212 { 00213 m_uri = m_url.substr(0,spl); 00214 m_query_string = m_url.substr(spl + 1); 00215 } 00216 else 00217 { 00218 m_uri = m_url; 00219 m_query_string = ""; 00220 } 00221 m_http_version = pa.getword(); 00222 m_b_http_1_1 = m_http_version.size() > 4 && m_http_version.substr(4) == "/1.1"; 00223 m_b_keepalive = m_b_http_1_1; 00224 m_request = true; 00225 } 00226 m_first = false; 00227 OnFirst(); 00228 return; 00229 } 00230 if (!line.size()) 00231 { 00232 if (m_body_size_left || !m_b_http_1_1 || !m_b_keepalive || m_b_chunked) 00233 { 00234 SetLineProtocol(false); 00235 m_header = false; 00236 } 00237 OnHeaderComplete(); 00238 if (!m_body_size_left && !m_b_chunked) 00239 { 00240 OnDataComplete(); 00241 } 00242 return; 00243 } 00244 Parse pa(line,":"); 00245 std::string key = pa.getword(); 00246 std::string value = pa.getrest(); 00247 OnHeader(key,value); 00248 if (Utility::ToLower(key) == "content-length") 00249 { 00250 m_body_size_left = atol(value.c_str()); 00251 } 00252 if (m_b_http_1_1 && Utility::ToLower(key) == "connection") 00253 { 00254 m_b_keepalive = Utility::ToLower(value) != "close"; 00255 } 00256 if (Utility::ToLower(key) == "transfer-encoding" && Utility::ToLower(value) == "chunked") 00257 { 00258 m_b_chunked = true; 00259 } 00260 /* If remote end tells us to keep connection alive, and we're operating 00261 in http/1.1 mode (not http/1.0 mode), then we mark the socket to be 00262 retained. */ 00263 #ifdef ENABLE_POOL 00264 if (m_b_http_1_1 && m_b_keepalive) 00265 { 00266 SetRetain(); 00267 } 00268 #endif 00269 if (m_header_count++ > m_max_header_count) 00270 { 00271 SetCloseAndDelete(); 00272 Handler().LogError(this, "OnLine", m_header_count, "http header count exceeds builtin limit of (" + Utility::l2string(m_max_header_count) + ")", LOG_LEVEL_FATAL); 00273 } 00274 }
virtual void HTTPSocket::OnFirst | ( | ) | [pure virtual] |
Callback executes when first line has been received.
GetMethod, GetUrl/GetUri, and GetHttpVersion are valid when this callback is executed.
Implemented in HttpBaseSocket, HttpClientSocket, HttpDebugSocket, and HttpdSocket.
Referenced by OnLine().
virtual void HTTPSocket::OnHeader | ( | const std::string & | key, | |
const std::string & | value | |||
) | [pure virtual] |
For each header line this callback is executed.
key | Http header name | |
value | Http header value |
Implemented in HttpBaseSocket, HttpClientSocket, HttpDebugSocket, and HttpdSocket.
Referenced by OnLine().
virtual void HTTPSocket::OnHeaderComplete | ( | ) | [pure virtual] |
Callback fires when all http headers have been received.
Implemented in HttpBaseSocket, HttpClientSocket, HttpDebugSocket, and HttpdSocket.
Referenced by OnLine().
virtual void HTTPSocket::OnData | ( | const char * | , | |
size_t | ||||
) | [pure virtual] |
Chunk of http body data recevied.
Implemented in HttpBaseSocket, HttpClientSocket, HttpDebugSocket, and HttpdSocket.
Referenced by OnRawData().
virtual void HTTPSocket::OnDataComplete | ( | ) | [inline, virtual] |
The full request/response body has been received.
Reimplemented in HttpDebugSocket.
Definition at line 70 of file HTTPSocket.h.
Referenced by OnLine(), and OnRawData().
const std::string & HTTPSocket::GetMethod | ( | ) | const |
Get http method from incoming request, ie GET/POST/PUT etc.
Definition at line 356 of file HTTPSocket.cpp.
References m_method.
Referenced by HttpDebugSocket::OnFirst(), HttpBaseSocket::OnFirst(), and HttpdSocket::OnHeaderComplete().
00357 { 00358 return m_method; 00359 }
const std::string & HTTPSocket::GetUrl | ( | ) | const |
Get url from request.
Definition at line 368 of file HTTPSocket.cpp.
References m_url.
Referenced by HttpDebugSocket::OnFirst().
00369 { 00370 return m_url; 00371 }
const std::string & HTTPSocket::GetUri | ( | ) | const |
Get part of url before '?' character.
Definition at line 380 of file HTTPSocket.cpp.
References m_uri.
Referenced by HttpdSocket::OnData(), HttpBaseSocket::OnFirst(), and HttpdSocket::OnHeaderComplete().
00381 { 00382 return m_uri; 00383 }
const std::string & HTTPSocket::GetQueryString | ( | ) | const |
Get part of url after '?' character.
Definition at line 386 of file HTTPSocket.cpp.
References m_query_string.
Referenced by HttpBaseSocket::OnFirst(), and HttpdSocket::OnHeaderComplete().
00387 { 00388 return m_query_string; 00389 }
const std::string & HTTPSocket::GetHttpVersion | ( | ) | const |
Get http version from incoming request/response.
Definition at line 392 of file HTTPSocket.cpp.
References m_http_version.
Referenced by HttpDebugSocket::OnFirst(), HttpClientSocket::OnFirst(), and HttpBaseSocket::OnFirst().
00393 { 00394 return m_http_version; 00395 }
const std::string & HTTPSocket::GetStatus | ( | ) | const |
Get http status from incoming response.
Definition at line 398 of file HTTPSocket.cpp.
References m_status.
Referenced by HttpClientSocket::OnFirst().
00399 { 00400 return m_status; 00401 }
const std::string & HTTPSocket::GetStatusText | ( | ) | const |
Get http statustext from incoming response.
Definition at line 404 of file HTTPSocket.cpp.
References m_status_text.
Referenced by HttpClientSocket::OnFirst().
00405 { 00406 return m_status_text; 00407 }
bool HTTPSocket::IsRequest | ( | ) | const |
Incoming header has been identified as a request (method url http_version
).
Definition at line 410 of file HTTPSocket.cpp.
References m_request.
00411 { 00412 return m_request; 00413 }
bool HTTPSocket::IsResponse | ( | ) | const |
Incoming header has been identified as a response (http_version status status_text
).
Definition at line 416 of file HTTPSocket.cpp.
References m_response.
Referenced by HttpClientSocket::OnFirst().
00417 { 00418 return m_response; 00419 }
void HTTPSocket::SetHttpVersion | ( | const std::string & | x | ) |
Set http version to be used in outgoing request/response.
Definition at line 422 of file HTTPSocket.cpp.
References m_http_version.
Referenced by HttpPostSocket::DoMultipartPost(), HttpBaseSocket::IHttpServer_Respond(), HttpPutSocket::OnConnect(), and HttpPostSocket::OnConnect().
00423 { 00424 m_http_version = x; 00425 }
void HTTPSocket::SetStatus | ( | const std::string & | x | ) |
Set http status for outgoing response.
Definition at line 428 of file HTTPSocket.cpp.
References m_status.
Referenced by HttpBaseSocket::IHttpServer_Respond(), HttpdSocket::OnHeaderComplete(), and HttpdSocket::Send64().
00429 { 00430 m_status = x; 00431 }
void HTTPSocket::SetStatusText | ( | const std::string & | x | ) |
Set http statustext for outgoing response.
Definition at line 434 of file HTTPSocket.cpp.
References m_status_text.
Referenced by HttpBaseSocket::IHttpServer_Respond(), HttpdSocket::OnHeaderComplete(), and HttpdSocket::Send64().
00435 { 00436 m_status_text = x; 00437 }
void HTTPSocket::AddResponseHeader | ( | const std::string & | x, | |
const std::string & | y | |||
) |
Add (and replace if exists) http header.
Definition at line 440 of file HTTPSocket.cpp.
References m_response_header.
Referenced by HttpPostSocket::DoMultipartPost(), HttpBaseSocket::IHttpServer_Respond(), HttpPutSocket::OnConnect(), HttpPostSocket::OnConnect(), HttpGetSocket::OnConnect(), HttpdSocket::OnData(), HttpdSocket::OnHeaderComplete(), HttpdSocket::Send64(), and url_this().
00441 { 00442 m_response_header[x] = y; 00443 }
void HTTPSocket::AddResponseHeader | ( | const std::string & | x, | |
const char * | format, | |||
... | ||||
) |
Add (and replace if exists) http header.
Definition at line 296 of file HTTPSocket.cpp.
References m_response_header.
00297 { 00298 char slask[8192]; // temporary for vsprintf / vsnprintf 00299 va_list ap; 00300 00301 va_start(ap, format); 00302 vsnprintf(slask, sizeof(slask), format, ap); 00303 va_end(ap); 00304 00305 m_response_header[header] = slask; 00306 }
void HTTPSocket::AppendResponseHeader | ( | const std::string & | x, | |
const std::string & | y | |||
) |
Add http header.
Definition at line 446 of file HTTPSocket.cpp.
References m_response_header_append.
Referenced by HttpBaseSocket::IHttpServer_Respond().
00447 { 00448 m_response_header_append.push_back(std::pair<std::string, std::string>(x,y)); 00449 }
bool HTTPSocket::ResponseHeaderIsSet | ( | const std::string & | name | ) | const |
See if http header 'name' has been set.
Definition at line 507 of file HTTPSocket.cpp.
References m_response_header, and m_response_header_append.
Referenced by HttpBaseSocket::IHttpServer_Respond().
00508 { 00509 string_m::const_iterator it = m_response_header.find( name ); 00510 if (it != m_response_header.end()) 00511 { 00512 return true; 00513 } 00514 std::list<std::pair<std::string, std::string> >::const_iterator it2; 00515 for (it2 = m_response_header_append.begin(); it2 != m_response_header_append.end(); ++it2) 00516 { 00517 const std::pair<std::string, std::string>& ref = *it2; 00518 if (!strcasecmp(ref.first.c_str(), name.c_str()) ) 00519 { 00520 return true; 00521 } 00522 } 00523 return false; 00524 }
void HTTPSocket::SendResponse | ( | ) |
Send response prepared with calls to methods SetHttpVersion, SetStatus, SetStatusText, and AddResponseHeader.
Definition at line 277 of file HTTPSocket.cpp.
References m_http_version, m_response_header, m_response_header_append, m_status, m_status_text, and TcpSocket::Send().
Referenced by HttpBaseSocket::IHttpServer_Respond(), HttpdSocket::OnHeaderComplete(), and HttpdSocket::Send64().
00278 { 00279 std::string msg; 00280 msg = m_http_version + " " + m_status + " " + m_status_text + "\r\n"; 00281 for (string_m::iterator it = m_response_header.begin(); it != m_response_header.end(); ++it) 00282 { 00283 std::string key = (*it).first; 00284 std::string val = (*it).second; 00285 msg += key + ": " + val + "\r\n"; 00286 } 00287 for (std::list<std::pair<std::string, std::string> >::iterator it2 = m_response_header_append.begin(); it2 != m_response_header_append.end(); ++it2) 00288 { 00289 msg += it2 -> first + ": " + it2 -> second + "\r\n"; 00290 } 00291 msg += "\r\n"; 00292 Send( msg ); 00293 }
void HTTPSocket::SendRequest | ( | ) |
Send request prepared with calls to methods SetMethod, SetUrl, SetHttpVersion, and AddResponseHeader.
Definition at line 309 of file HTTPSocket.cpp.
References m_http_version, m_method, m_response_header, m_url, and TcpSocket::Send().
Referenced by HttpPostSocket::DoMultipartPost(), HttpPutSocket::OnConnect(), HttpPostSocket::OnConnect(), and HttpGetSocket::OnConnect().
00310 { 00311 std::string msg; 00312 msg = m_method + " " + m_url + " " + m_http_version + "\r\n"; 00313 for (string_m::iterator it = m_response_header.begin(); it != m_response_header.end(); ++it) 00314 { 00315 std::string key = (*it).first; 00316 std::string val = (*it).second; 00317 msg += key + ": " + val + "\r\n"; 00318 } 00319 msg += "\r\n"; 00320 Send( msg ); 00321 }
std::string HTTPSocket::MyUseragent | ( | ) | [virtual] |
Implement this to return your own User-agent string.
Definition at line 324 of file HTTPSocket.cpp.
Referenced by HttpPostSocket::DoMultipartPost(), HttpPutSocket::OnConnect(), HttpPostSocket::OnConnect(), and HttpGetSocket::OnConnect().
00325 { 00326 std::string version = "C++Sockets/"; 00327 #ifdef _VERSION 00328 version += _VERSION; 00329 #endif 00330 return version; 00331 }
void HTTPSocket::url_this | ( | const std::string & | url_in, | |
std::string & | protocol, | |||
std::string & | host, | |||
port_t & | port, | |||
std::string & | url, | |||
std::string & | file | |||
) |
Parse url.
If protocol is https, EnableSSL() will be called.
Definition at line 458 of file HTTPSocket.cpp.
References AddResponseHeader(), Utility::base64(), Socket::EnableSSL(), Parse::getrest(), Parse::getvalue(), Parse::getword(), Socket::Handler(), LOG_LEVEL_WARNING, and ISocketHandler::LogError().
Referenced by HttpClientSocket::HttpClientSocket(), and HttpClientSocket::Url().
00459 { 00460 Parse pa(url_in,"/"); 00461 std::string user; 00462 std::string auth; 00463 protocol = pa.getword(); // http 00464 if (!strcasecmp(protocol.c_str(), "https:")) 00465 { 00466 #ifdef HAVE_OPENSSL 00467 EnableSSL(); 00468 #else 00469 Handler().LogError(this, "url_this", -1, "SSL not available", LOG_LEVEL_WARNING); 00470 #endif 00471 port = 443; 00472 } 00473 else 00474 { 00475 port = 80; 00476 } 00477 host = pa.getword(); 00478 size_t pos = host.find("@"); 00479 if (pos != std::string::npos) 00480 { 00481 user = host.substr(0, pos); 00482 host = host.substr(pos + 1); 00483 if (user.find(":") != std::string::npos) 00484 { 00485 AddResponseHeader("Authorization", "Basic " + Utility::base64(user)); 00486 } 00487 } 00488 if (strstr(host.c_str(),":")) 00489 { 00490 Parse pa(host,":"); 00491 pa.getword(host); 00492 port = static_cast<port_t>(pa.getvalue()); 00493 } 00494 url = "/" + pa.getrest(); 00495 { 00496 Parse pa(url,"/"); 00497 std::string tmp = pa.getword(); 00498 while (tmp.size()) 00499 { 00500 file = tmp; 00501 tmp = pa.getword(); 00502 } 00503 } 00504 } // url_this
bool HTTPSocket::IsChunked | ( | ) | const [inline] |
Transfer coding 'chunked'.
Definition at line 121 of file HTTPSocket.h.
Referenced by HttpDebugSocket::OnHeaderComplete().
00121 { return m_b_chunked; }
void HTTPSocket::Reset | ( | ) | [protected, virtual] |
Reset state of socket to sucessfully implement keep-alive.
Reimplemented in HttpBaseSocket, and HttpdSocket.
Definition at line 334 of file HTTPSocket.cpp.
References m_first, m_header, m_header_count, m_request, m_response, m_response_header, m_response_header_append, and TcpSocket::SetLineProtocol().
Referenced by HttpdSocket::Reset(), and HttpBaseSocket::Reset().
00335 { 00336 m_first = true; 00337 m_header = true; 00338 m_request = false; 00339 m_response = false; 00340 SetLineProtocol(true); 00341 while (m_response_header.size()) 00342 { 00343 string_m::iterator it = m_response_header.begin(); 00344 m_response_header.erase(it); 00345 } 00346 while (m_response_header_append.size()) 00347 { 00348 std::list<std::pair<std::string, std::string> >::iterator it = m_response_header_append.begin(); 00349 m_response_header_append.erase(it); 00350 } 00351 m_header_count = 0; 00352 00353 }
void HTTPSocket::SetMaxHeaderCount | ( | int | x | ) | [inline, protected] |
void HTTPSocket::SetMethod | ( | const std::string & | x | ) | [protected] |
Set http method to be used in request.
Definition at line 362 of file HTTPSocket.cpp.
References m_method.
Referenced by HttpPostSocket::DoMultipartPost(), HttpPutSocket::OnConnect(), HttpPostSocket::OnConnect(), and HttpGetSocket::OnConnect().
00363 { 00364 m_method = x; 00365 }
void HTTPSocket::SetUrl | ( | const std::string & | x | ) | [protected] |
Set url to be used in outgoing request.
Definition at line 374 of file HTTPSocket.cpp.
References m_url.
Referenced by HttpClientSocket::HttpClientSocket(), HttpGetSocket::HttpGetSocket(), and HttpClientSocket::Url().
00375 { 00376 m_url = x; 00377 }
void HTTPSocket::SetUri | ( | const std::string & | x | ) | [protected] |
Now why would I need this when there is a SetUrl method?
Definition at line 452 of file HTTPSocket.cpp.
References m_uri.
00453 { 00454 m_uri = x; 00455 }
HTTPSocket& HTTPSocket::operator= | ( | const HTTPSocket & | ) | [inline, private] |
bool HTTPSocket::m_first [private] |
bool HTTPSocket::m_header [private] |
std::string HTTPSocket::m_line [private] |
Current line in line protocol mode.
Reimplemented from TcpSocket.
Definition at line 141 of file HTTPSocket.h.
std::string HTTPSocket::m_method [private] |
Definition at line 142 of file HTTPSocket.h.
Referenced by GetMethod(), OnLine(), SendRequest(), and SetMethod().
std::string HTTPSocket::m_url [private] |
Definition at line 143 of file HTTPSocket.h.
Referenced by GetUrl(), OnLine(), SendRequest(), and SetUrl().
std::string HTTPSocket::m_uri [private] |
std::string HTTPSocket::m_query_string [private] |
std::string HTTPSocket::m_http_version [private] |
Definition at line 146 of file HTTPSocket.h.
Referenced by GetHttpVersion(), OnLine(), SendRequest(), SendResponse(), and SetHttpVersion().
std::string HTTPSocket::m_status [private] |
Definition at line 147 of file HTTPSocket.h.
Referenced by GetStatus(), OnLine(), SendResponse(), and SetStatus().
std::string HTTPSocket::m_status_text [private] |
Definition at line 148 of file HTTPSocket.h.
Referenced by GetStatusText(), OnLine(), SendResponse(), and SetStatusText().
bool HTTPSocket::m_request [private] |
bool HTTPSocket::m_response [private] |
string_m HTTPSocket::m_response_header [private] |
Definition at line 151 of file HTTPSocket.h.
Referenced by AddResponseHeader(), Reset(), ResponseHeaderIsSet(), SendRequest(), and SendResponse().
size_t HTTPSocket::m_body_size_left [private] |
Reimplemented in HttpBaseSocket.
Definition at line 152 of file HTTPSocket.h.
Referenced by OnLine(), and OnRawData().
bool HTTPSocket::m_b_http_1_1 [private] |
bool HTTPSocket::m_b_keepalive [private] |
Reimplemented in HttpBaseSocket.
Definition at line 154 of file HTTPSocket.h.
Referenced by OnLine(), and OnRawData().
std::list<std::pair<std::string, std::string> > HTTPSocket::m_response_header_append [private] |
Definition at line 155 of file HTTPSocket.h.
Referenced by AppendResponseHeader(), Reset(), ResponseHeaderIsSet(), and SendResponse().
bool HTTPSocket::m_b_chunked [private] |
size_t HTTPSocket::m_chunk_size [private] |
int HTTPSocket::m_chunk_state [private] |
std::string HTTPSocket::m_chunk_line [private] |
int HTTPSocket::m_header_count [private] |
int HTTPSocket::m_max_header_count [private] |