bool HTTPServer_Impl::read_lines(TCPConnection &connection, std::string &out_header_lines) { out_header_lines.clear(); while (out_header_lines.length() < 32*1024) { char buffer[1024]; if (connection.get_read_event().wait(15000) == false) throw Exception("Read timed out"); int bytes_read = connection.peek(buffer, 1024); if (bytes_read <= 0) break; std::string str(buffer, bytes_read); std::string::size_type start_pos = out_header_lines.length(); out_header_lines += str; std::string::size_type pos = out_header_lines.find("\r\n\r\n"); if (pos == std::string::npos) { connection.receive(buffer, bytes_read); } else { connection.receive(buffer, pos+4-start_pos); out_header_lines.resize(pos+4); return true; } } return false; }