X Tutup
#include "Test.h" bool test(HttpServer::ServerRequest &request, HttpServer::ServerResponse &response) { // Output incoming headers std::string s = R"( )"; for (auto const &pair : request.headers) { s += R"( )"; } // Output incoming data s += R"( )"; for (auto const &pair : request.data) { s += R"( )"; } // Output incoming url parameters s += R"( )"; for (auto const &pair : request.params) { s += R"( )"; } // Output info about incoming files s += R"( )"; for (auto const &pair : request.files) { const HttpServer::FileIncoming &file = pair.second; s += R"( )"; } s += R"(
Incoming headers
)" + pair.first + R"( )" + pair.second + R"(
Incoming data
)" + pair.first + R"( )" + pair.second + R"(
Incoming url parameters
)" + pair.first + R"( )" + pair.second + R"(
Incoming files
)" + file.getName() + R"( )" + std::to_string(file.getSize() ) + R"(
)"; HttpServer::SocketAdapter &socket = response.socket; std::map &headers_outgoing = response.headers; // Set outgoing headers headers_outgoing[""] = "HTTP/1.1 200 OK"; headers_outgoing["Content-Type"] = "text/html; charset=utf-8"; headers_outgoing["Accept-Ranges"] = "bytes"; headers_outgoing["Content-Length"] = std::to_string(s.length() ); headers_outgoing["Connection"] = "Keep-Alive"; headers_outgoing["Date"] = Utils::getDatetimeAsString(); std::string headers; for (auto const &h : headers_outgoing) { if (h.first.length() ) { headers += h.first + ": "; } headers += h.second + "\r\n"; } headers += "\r\n"; // Send headers and page const std::chrono::milliseconds timeout(5000); socket.nonblock_send(headers, timeout); socket.nonblock_send(s, timeout); return EXIT_SUCCESS; }
X Tutup