void HTTPSocket::OnLine(const std::string& line) { if (m_first) { Parse pa(line); std::string str = pa.getword(); if (str.substr(0,4) == "HTTP") // response { m_http_version = str; m_status = pa.getword(); m_status_text = pa.getrest(); m_response = true; } else // request { m_method = str; m_url = pa.getword(); size_t spl = m_url.find("?"); if (spl != std::string::npos) { m_uri = m_url.substr(0,spl); m_query_string = m_url.substr(spl + 1); } else { m_uri = m_url; } m_http_version = pa.getword(); m_request = true; } m_first = false; OnFirst(); return; } if (!line.size()) { // SetLineProtocol(false); m_header = false; OnHeaderComplete(); return; } Parse pa(line,":"); std::string key = pa.getword(); std::string value = pa.getrest(); OnHeader(key,value); /* If remote end tells us to keep connection alive, and we're operating in http/1.1 mode (not http/1.0 mode), then we mark the socket to be retained. */ /* if (!strcasecmp(key.c_str(), "connection") && !strcasecmp(value.c_str(), "keep-alive") ) { SetRetain(); }*/ }
void CExternalIPResolver::OnReceive() { if (!m_pRecvBuffer) { m_pRecvBuffer = new char[m_recvBufferLen]; m_recvBufferPos = 0; } if (m_pSendBuffer) return; while (m_pSocket) { unsigned int len = m_recvBufferLen - m_recvBufferPos; int error; int read = m_pSocket->Read(m_pRecvBuffer + m_recvBufferPos, len, error); if (read == -1) { if (error != EAGAIN) Close(false); return; } if (!read) { Close(false); return; } if (m_finished) { // Just ignore all further data m_recvBufferPos = 0; return; } m_recvBufferPos += read; if (!m_gotHeader) OnHeader(); else { if (m_transferEncoding == chunked) OnChunkedData(); else OnData(m_pRecvBuffer, m_recvBufferPos); } } }
void HTTPSocket::OnLine(const std::string& line) { if (m_first) { Parse pa(line); std::string str = pa.getword(); if (str.size() > 4 && Utility::ToLower(str.substr(0,5)) == "http/") // response { m_http_version = str; m_status = pa.getword(); m_status_text = pa.getrest(); m_response = true; } else // request { m_method = str; m_url = pa.getword(); size_t spl = m_url.find("?"); if (spl != std::string::npos) { m_uri = m_url.substr(0,spl); m_query_string = m_url.substr(spl + 1); } else { m_uri = m_url; m_query_string = ""; } m_http_version = pa.getword(); m_b_http_1_1 = m_http_version.size() > 4 && m_http_version.substr(4) == "/1.1"; m_b_keepalive = m_b_http_1_1; m_request = true; } m_first = false; OnFirst(); return; } if (!line.size()) { if (m_body_size_left || !m_b_http_1_1 || !m_b_keepalive || m_b_chunked) { SetLineProtocol(false); m_header = false; } OnHeaderComplete(); if (!m_body_size_left && !m_b_chunked) { OnDataComplete(); } return; } Parse pa(line,":"); std::string key = pa.getword(); std::string value = pa.getrest(); OnHeader(key,value); if (Utility::ToLower(key) == "content-length") { m_body_size_left = atol(value.c_str()); } if (m_b_http_1_1 && Utility::ToLower(key) == "connection") { m_b_keepalive = Utility::ToLower(value) != "close"; } if (Utility::ToLower(key) == "transfer-encoding" && Utility::ToLower(value) == "chunked") { m_b_chunked = true; } /* If remote end tells us to keep connection alive, and we're operating in http/1.1 mode (not http/1.0 mode), then we mark the socket to be retained. */ #ifdef ENABLE_POOL if (m_b_http_1_1 && m_b_keepalive) { SetRetain(); } #endif }