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 () |
| Get http method from incoming request, ie GET/POST/PUT etc. | |
| void | SetMethod (const std::string &x) |
| Set http method to be used in request. | |
| const std::string & | GetUrl () |
| Get url from request. | |
| void | SetUrl (const std::string &x) |
| Set url to be used in outgoing request. | |
| const std::string & | GetUri () |
| Get part of url before '?' character. | |
| void | SetUri (const std::string &x) |
| Now why would I need this when there is a SetUrl method? | |
| const std::string & | GetQueryString () |
| Get part of url after '?' character. | |
| const std::string & | GetHttpVersion () |
| Get http version from incoming request/response. | |
| const std::string & | GetStatus () |
| Get http status from incoming response. | |
| const std::string & | GetStatusText () |
| Get http statustext from incoming response. | |
| bool | IsRequest () |
| Incoming header has been identified as a request (method url http_version ). | |
| bool | IsResponse () |
| 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) |
| 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 () |
| Transfer coding 'chunked'. | |
Protected Member Functions | |
| HTTPSocket (const HTTPSocket &s) | |
| virtual void | Reset () |
| Reset state of socket to sucessfully implement keep-alive. | |
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 |
Definition at line 45 of file HTTPSocket.h.
typedef Utility::ncmap<std::string> HTTPSocket::string_m [private] |
| HTTPSocket::HTTPSocket | ( | ISocketHandler & | h | ) |
Definition at line 44 of file HTTPSocket.cpp.
References TcpSocket::DisableInputBuffer(), and TcpSocket::SetLineProtocol().
00045 :TcpSocket(h) 00046 ,m_first(true) 00047 ,m_header(true) 00048 ,m_http_version("HTTP/1.0") 00049 ,m_request(false) 00050 ,m_response(false) 00051 ,m_body_size_left(0) 00052 ,m_b_http_1_1(false) 00053 ,m_b_keepalive(false) 00054 ,m_b_chunked(false) 00055 ,m_chunk_size(0) 00056 ,m_chunk_state(0) 00057 { 00058 SetLineProtocol(); 00059 DisableInputBuffer(); 00060 }
| 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 68 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.
00069 { 00070 if (!m_header) 00071 { 00072 if (m_b_chunked) 00073 { 00074 size_t ptr = 0; 00075 while (ptr < len) 00076 { 00077 switch (m_chunk_state) 00078 { 00079 case 4: 00080 while (ptr < len && (m_chunk_line.size() < 2 || m_chunk_line.substr(m_chunk_line.size() - 2) != "\r\n")) 00081 m_chunk_line += buf[ptr++]; 00082 if (m_chunk_line.size() > 1 && m_chunk_line.substr(m_chunk_line.size() - 2) == "\r\n") 00083 { 00084 OnDataComplete(); 00085 // prepare for next request(or response) 00086 m_b_chunked = false; 00087 SetLineProtocol( true ); 00088 m_first = true; 00089 m_header = true; 00090 m_body_size_left = 0; 00091 if (len - ptr > 0) 00092 { 00093 char tmp[TCP_BUFSIZE_READ]; 00094 memcpy(tmp, buf + ptr, len - ptr); 00095 tmp[len - ptr] = 0; 00096 OnRead( tmp, len - ptr ); 00097 ptr = len; 00098 } 00099 } 00100 break; 00101 case 0: 00102 while (ptr < len && (m_chunk_line.size() < 2 || m_chunk_line.substr(m_chunk_line.size() - 2) != "\r\n")) 00103 m_chunk_line += buf[ptr++]; 00104 if (m_chunk_line.size() > 1 && m_chunk_line.substr(m_chunk_line.size() - 2) == "\r\n") 00105 { 00106 m_chunk_line.resize(m_chunk_line.size() - 2); 00107 Parse pa(m_chunk_line, ";"); 00108 std::string size_str = pa.getword(); 00109 m_chunk_size = Utility::hex2unsigned(size_str); 00110 if (!m_chunk_size) 00111 { 00112 m_chunk_state = 4; 00113 m_chunk_line = ""; 00114 } 00115 else 00116 { 00117 m_chunk_state = 1; 00118 m_chunk_line = ""; 00119 } 00120 } 00121 break; 00122 case 1: 00123 { 00124 size_t left = len - ptr; 00125 size_t sz = m_chunk_size < left ? m_chunk_size : left; 00126 OnData(buf + ptr, sz); 00127 m_chunk_size -= sz; 00128 ptr += sz; 00129 if (!m_chunk_size) 00130 { 00131 m_chunk_state = 2; 00132 } 00133 } 00134 break; 00135 case 2: // skip CR 00136 ptr++; 00137 m_chunk_state = 3; 00138 break; 00139 case 3: // skip LF 00140 ptr++; 00141 m_chunk_state = 0; 00142 break; 00143 } 00144 } 00145 } 00146 else 00147 if (!m_b_http_1_1 || !m_b_keepalive) 00148 { 00149 OnData(buf, len); 00150 /* 00151 request is HTTP/1.0 _or_ HTTP/1.1 and not keep-alive 00152 00153 This means we destroy the connection after the response has been delivered, 00154 hence no need to reset all internal state variables for a new incoming 00155 request. 00156 */ 00157 m_body_size_left -= len; 00158 if (!m_body_size_left) 00159 { 00160 OnDataComplete(); 00161 } 00162 } 00163 else 00164 { 00165 size_t sz = m_body_size_left < len ? m_body_size_left : len; 00166 OnData(buf, sz); 00167 m_body_size_left -= sz; 00168 if (!m_body_size_left) 00169 { 00170 OnDataComplete(); 00171 // prepare for next request(or response) 00172 SetLineProtocol( true ); 00173 m_first = true; 00174 m_header = true; 00175 m_body_size_left = 0; 00176 if (len - sz > 0) 00177 { 00178 char tmp[TCP_BUFSIZE_READ]; 00179 memcpy(tmp, buf + sz, len - sz); 00180 tmp[len - sz] = 0; 00181 OnRead( tmp, len - sz ); 00182 } 00183 } 00184 } 00185 } 00186 }
| 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 189 of file HTTPSocket.cpp.
References Parse::getrest(), Parse::getword(), m_b_chunked, m_b_http_1_1, m_b_keepalive, m_body_size_left, m_first, m_header, m_http_version, m_method, m_query_string, m_request, m_response, m_status, m_status_text, m_uri, m_url, OnDataComplete(), OnFirst(), OnHeader(), OnHeaderComplete(), TcpSocket::SetLineProtocol(), Socket::SetRetain(), and Utility::ToLower().
00190 { 00191 if (m_first) 00192 { 00193 Parse pa(line); 00194 std::string str = pa.getword(); 00195 if (str.size() > 4 && Utility::ToLower(str.substr(0,5)) == "http/") // response 00196 { 00197 m_http_version = str; 00198 m_status = pa.getword(); 00199 m_status_text = pa.getrest(); 00200 m_response = true; 00201 } 00202 else // request 00203 { 00204 m_method = str; 00205 m_url = pa.getword(); 00206 size_t spl = m_url.find("?"); 00207 if (spl != std::string::npos) 00208 { 00209 m_uri = m_url.substr(0,spl); 00210 m_query_string = m_url.substr(spl + 1); 00211 } 00212 else 00213 { 00214 m_uri = m_url; 00215 m_query_string = ""; 00216 } 00217 m_http_version = pa.getword(); 00218 m_b_http_1_1 = m_http_version.size() > 4 && m_http_version.substr(4) == "/1.1"; 00219 m_b_keepalive = m_b_http_1_1; 00220 m_request = true; 00221 } 00222 m_first = false; 00223 OnFirst(); 00224 return; 00225 } 00226 if (!line.size()) 00227 { 00228 if (m_body_size_left || !m_b_http_1_1 || !m_b_keepalive || m_b_chunked) 00229 { 00230 SetLineProtocol(false); 00231 m_header = false; 00232 } 00233 OnHeaderComplete(); 00234 if (!m_body_size_left && !m_b_chunked) 00235 { 00236 OnDataComplete(); 00237 } 00238 return; 00239 } 00240 Parse pa(line,":"); 00241 std::string key = pa.getword(); 00242 std::string value = pa.getrest(); 00243 OnHeader(key,value); 00244 if (Utility::ToLower(key) == "content-length") 00245 { 00246 m_body_size_left = atol(value.c_str()); 00247 } 00248 if (m_b_http_1_1 && Utility::ToLower(key) == "connection") 00249 { 00250 m_b_keepalive = Utility::ToLower(value) != "close"; 00251 } 00252 if (Utility::ToLower(key) == "transfer-encoding" && Utility::ToLower(value) == "chunked") 00253 { 00254 m_b_chunked = true; 00255 } 00256 /* If remote end tells us to keep connection alive, and we're operating 00257 in http/1.1 mode (not http/1.0 mode), then we mark the socket to be 00258 retained. */ 00259 #ifdef ENABLE_POOL 00260 if (m_b_http_1_1 && m_b_keepalive) 00261 { 00262 SetRetain(); 00263 } 00264 #endif 00265 }
| 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 68 of file HTTPSocket.h.
Referenced by OnLine(), and OnRawData().
| const std::string & HTTPSocket::GetMethod | ( | ) |
Get http method from incoming request, ie GET/POST/PUT etc.
Definition at line 350 of file HTTPSocket.cpp.
References m_method.
Referenced by HttpDebugSocket::OnFirst(), HttpBaseSocket::OnFirst(), and HttpdSocket::OnHeaderComplete().
00351 { 00352 return m_method; 00353 }
| void HTTPSocket::SetMethod | ( | const std::string & | x | ) |
Set http method to be used in request.
Definition at line 356 of file HTTPSocket.cpp.
References m_method.
Referenced by HttpPostSocket::DoMultipartPost(), HttpPutSocket::OnConnect(), HttpPostSocket::OnConnect(), and HttpGetSocket::OnConnect().
00357 { 00358 m_method = x; 00359 }
| const std::string & HTTPSocket::GetUrl | ( | ) |
Get url from request.
Definition at line 362 of file HTTPSocket.cpp.
References m_url.
Referenced by HttpDebugSocket::OnFirst().
00363 { 00364 return m_url; 00365 }
| void HTTPSocket::SetUrl | ( | const std::string & | x | ) |
Set url to be used in outgoing request.
Definition at line 368 of file HTTPSocket.cpp.
References m_url.
Referenced by HttpClientSocket::HttpClientSocket(), HttpGetSocket::HttpGetSocket(), and HttpClientSocket::Url().
00369 { 00370 m_url = x; 00371 }
| const std::string & HTTPSocket::GetUri | ( | ) |
Get part of url before '?' character.
Definition at line 374 of file HTTPSocket.cpp.
References m_uri.
Referenced by HttpdSocket::OnData(), HttpBaseSocket::OnFirst(), and HttpdSocket::OnHeaderComplete().
00375 { 00376 return m_uri; 00377 }
| void HTTPSocket::SetUri | ( | const std::string & | x | ) |
Now why would I need this when there is a SetUrl method?
Definition at line 446 of file HTTPSocket.cpp.
References m_uri.
00447 { 00448 m_uri = x; 00449 }
| const std::string & HTTPSocket::GetQueryString | ( | ) |
Get part of url after '?' character.
Definition at line 380 of file HTTPSocket.cpp.
References m_query_string.
Referenced by HttpBaseSocket::OnFirst(), and HttpdSocket::OnHeaderComplete().
00381 { 00382 return m_query_string; 00383 }
| const std::string & HTTPSocket::GetHttpVersion | ( | ) |
Get http version from incoming request/response.
Definition at line 386 of file HTTPSocket.cpp.
References m_http_version.
Referenced by HttpDebugSocket::OnFirst(), HttpClientSocket::OnFirst(), and HttpBaseSocket::OnFirst().
00387 { 00388 return m_http_version; 00389 }
| const std::string & HTTPSocket::GetStatus | ( | ) |
Get http status from incoming response.
Definition at line 392 of file HTTPSocket.cpp.
References m_status.
Referenced by HttpClientSocket::OnFirst().
00393 { 00394 return m_status; 00395 }
| const std::string & HTTPSocket::GetStatusText | ( | ) |
Get http statustext from incoming response.
Definition at line 398 of file HTTPSocket.cpp.
References m_status_text.
Referenced by HttpClientSocket::OnFirst().
00399 { 00400 return m_status_text; 00401 }
| bool HTTPSocket::IsRequest | ( | ) |
Incoming header has been identified as a request (method url http_version
).
Definition at line 404 of file HTTPSocket.cpp.
References m_request.
00405 { 00406 return m_request; 00407 }
| bool HTTPSocket::IsResponse | ( | ) |
Incoming header has been identified as a response (http_version status status_text
).
Definition at line 410 of file HTTPSocket.cpp.
References m_response.
Referenced by HttpClientSocket::OnFirst().
00411 { 00412 return m_response; 00413 }
| void HTTPSocket::SetHttpVersion | ( | const std::string & | x | ) |
Set http version to be used in outgoing request/response.
Definition at line 416 of file HTTPSocket.cpp.
References m_http_version.
Referenced by HttpPostSocket::DoMultipartPost(), HttpPutSocket::OnConnect(), HttpPostSocket::OnConnect(), and HttpBaseSocket::Respond().
00417 { 00418 m_http_version = x; 00419 }
| void HTTPSocket::SetStatus | ( | const std::string & | x | ) |
Set http status for outgoing response.
Definition at line 422 of file HTTPSocket.cpp.
References m_status.
Referenced by HttpdSocket::OnHeaderComplete(), HttpBaseSocket::Respond(), and HttpdSocket::Send64().
00423 { 00424 m_status = x; 00425 }
| void HTTPSocket::SetStatusText | ( | const std::string & | x | ) |
Set http statustext for outgoing response.
Definition at line 428 of file HTTPSocket.cpp.
References m_status_text.
Referenced by HttpdSocket::OnHeaderComplete(), HttpBaseSocket::Respond(), and HttpdSocket::Send64().
00429 { 00430 m_status_text = x; 00431 }
| void HTTPSocket::AddResponseHeader | ( | const std::string & | x, | |
| const std::string & | y | |||
| ) |
Add (and replace if exists) http header.
Definition at line 434 of file HTTPSocket.cpp.
References m_response_header.
Referenced by HttpPostSocket::DoMultipartPost(), HttpPutSocket::OnConnect(), HttpPostSocket::OnConnect(), HttpGetSocket::OnConnect(), HttpdSocket::OnData(), HttpdSocket::OnHeaderComplete(), HttpBaseSocket::Respond(), and HttpdSocket::Send64().
00435 { 00436 m_response_header[x] = y; 00437 }
| void HTTPSocket::AddResponseHeader | ( | const std::string & | x, | |
| const char * | format, | |||
| ... | ||||
| ) |
Add (and replace if exists) http header.
Definition at line 287 of file HTTPSocket.cpp.
References m_response_header.
00288 { 00289 char slask[5000]; // temporary for vsprintf / vsnprintf 00290 va_list ap; 00291 00292 va_start(ap, format); 00293 #ifdef _WIN32 00294 vsprintf(slask, format, ap); 00295 #else 00296 vsnprintf(slask, 5000, format, ap); 00297 #endif 00298 va_end(ap); 00299 00300 m_response_header[header] = slask; 00301 }
| void HTTPSocket::AppendResponseHeader | ( | const std::string & | x, | |
| const std::string & | y | |||
| ) |
Add http header.
Definition at line 440 of file HTTPSocket.cpp.
References m_response_header_append.
Referenced by HttpBaseSocket::Respond().
00441 { 00442 m_response_header_append.push_back(std::pair<std::string, std::string>(x,y)); 00443 }
| bool HTTPSocket::ResponseHeaderIsSet | ( | const std::string & | name | ) |
See if http header 'name' has been set.
Definition at line 489 of file HTTPSocket.cpp.
References m_response_header, and m_response_header_append.
Referenced by HttpBaseSocket::Respond().
00490 { 00491 string_m::iterator it = m_response_header.find( name ); 00492 if (it != m_response_header.end()) 00493 { 00494 return true; 00495 } 00496 std::list<std::pair<std::string, std::string> >::iterator it2; 00497 for (it2 = m_response_header_append.begin(); it2 != m_response_header_append.end(); it2++) 00498 { 00499 std::pair<std::string, std::string>& ref = *it2; 00500 if (!strcasecmp(ref.first.c_str(), name.c_str()) ) 00501 { 00502 return true; 00503 } 00504 } 00505 return false; 00506 }
| void HTTPSocket::SendResponse | ( | ) |
Send response prepared with calls to methods SetHttpVersion, SetStatus, SetStatusText, and AddResponseHeader.
Definition at line 268 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 HttpdSocket::OnHeaderComplete(), HttpBaseSocket::Respond(), and HttpdSocket::Send64().
00269 { 00270 std::string msg; 00271 msg = m_http_version + " " + m_status + " " + m_status_text + "\r\n"; 00272 for (string_m::iterator it = m_response_header.begin(); it != m_response_header.end(); it++) 00273 { 00274 std::string key = (*it).first; 00275 std::string val = (*it).second; 00276 msg += key + ": " + val + "\r\n"; 00277 } 00278 for (std::list<std::pair<std::string, std::string> >::iterator it2 = m_response_header_append.begin(); it2 != m_response_header_append.end(); ++it2) 00279 { 00280 msg += it2 -> first + ": " + it2 -> second + "\r\n"; 00281 } 00282 msg += "\r\n"; 00283 Send( msg ); 00284 }
| void HTTPSocket::SendRequest | ( | ) |
Send request prepared with calls to methods SetMethod, SetUrl, SetHttpVersion, and AddResponseHeader.
Definition at line 304 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().
00305 { 00306 std::string msg; 00307 msg = m_method + " " + m_url + " " + m_http_version + "\r\n"; 00308 for (string_m::iterator it = m_response_header.begin(); it != m_response_header.end(); it++) 00309 { 00310 std::string key = (*it).first; 00311 std::string val = (*it).second; 00312 msg += key + ": " + val + "\r\n"; 00313 } 00314 msg += "\r\n"; 00315 Send( msg ); 00316 }
| std::string HTTPSocket::MyUseragent | ( | ) | [virtual] |
Implement this to return your own User-agent string.
Definition at line 319 of file HTTPSocket.cpp.
Referenced by HttpPostSocket::DoMultipartPost(), HttpPutSocket::OnConnect(), HttpPostSocket::OnConnect(), and HttpGetSocket::OnConnect().
00320 { 00321 std::string version = "C++Sockets/"; 00322 #ifdef _VERSION 00323 version += _VERSION; 00324 #endif 00325 return version; 00326 }
| 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 452 of file HTTPSocket.cpp.
References Socket::EnableSSL(), Parse::getrest(), Parse::getvalue(), Parse::getword(), Socket::Handler(), LOG_LEVEL_WARNING, and ISocketHandler::LogError().
Referenced by HttpClientSocket::HttpClientSocket(), and HttpClientSocket::Url().
00453 { 00454 Parse pa(url_in,"/"); 00455 protocol = pa.getword(); // http 00456 if (!strcasecmp(protocol.c_str(), "https:")) 00457 { 00458 #ifdef HAVE_OPENSSL 00459 EnableSSL(); 00460 #else 00461 Handler().LogError(this, "url_this", -1, "SSL not available", LOG_LEVEL_WARNING); 00462 #endif 00463 port = 443; 00464 } 00465 else 00466 { 00467 port = 80; 00468 } 00469 host = pa.getword(); 00470 if (strstr(host.c_str(),":")) 00471 { 00472 Parse pa(host,":"); 00473 pa.getword(host); 00474 port = static_cast<port_t>(pa.getvalue()); 00475 } 00476 url = "/" + pa.getrest(); 00477 { 00478 Parse pa(url,"/"); 00479 std::string tmp = pa.getword(); 00480 while (tmp.size()) 00481 { 00482 file = tmp; 00483 tmp = pa.getword(); 00484 } 00485 } 00486 } // url_this
| bool HTTPSocket::IsChunked | ( | ) | [inline] |
Transfer coding 'chunked'.
Definition at line 122 of file HTTPSocket.h.
Referenced by HttpDebugSocket::OnHeaderComplete().
00122 { 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 329 of file HTTPSocket.cpp.
References m_first, m_header, m_request, m_response, m_response_header, m_response_header_append, and TcpSocket::SetLineProtocol().
Referenced by HttpdSocket::Reset(), and HttpBaseSocket::Reset().
00330 { 00331 m_first = true; 00332 m_header = true; 00333 m_request = false; 00334 m_response = false; 00335 SetLineProtocol(true); 00336 while (m_response_header.size()) 00337 { 00338 string_m::iterator it = m_response_header.begin(); <