示例#1
0
文件: main.cpp 项目: Joker-vD/sntlm
void print_response(HttpResponse& response, TcpClientSocket& socket) {
	std::cout << narrow(widen(response.getStatusLine(), CP_UTF8), CP_OEMCP) << std::endl;
	auto headers = response.getHeaders();
	for (auto it = std::begin(headers), eit = std::end(headers); it != eit; ++it) {
		for (auto vit = std::begin(it->second), veit = std::end(it->second); vit != veit; ++vit) {
			std::cout << it->first << ": " << *vit << std::endl;
		}
	}
	std::cout << "======END OF HEADERS======" << std::endl;

	auto& buffer = response.getBuffer();
	if (response.getIsChunked()) {
		std::cout << "[[CHUNKED ENCODING]]" << std::endl;
		for (auto chunk = buffer.getchunk(); !chunk.empty(); chunk = buffer.getchunk()) {
			std::cout << chunk;
		}
		std::cout << "[[TRAILING HEADERS]]" << std::endl;
		for (auto th = buffer.getline(); !th.empty(); th = buffer.getline()) {
			std::cout << th << std::endl;
		}
	}
	else if (HttpResponse::nlen != response.getContentLength()) {
		std::cout << "[[EXACTLY " << response.getContentLength() << " BYTES]]" << std::endl;
		std::cout << buffer.getcount(response.getContentLength()) << std::endl;
	}
	else {
		std::vector<BYTE> buff(8 * 1024, 0);
		for (auto last = socket.recv_upto(std::begin(buff), std::end(buff));
			last != std::begin(buff); last = socket.recv_upto(std::begin(buff), std::end(buff))) {
				std::cout << std::string(std::begin(buff), last);
		}
	}
	std::cout << std::endl << "======END OF RESPONSE======" << std::endl;
}