X Tutup
#include "Test.h" #include "../utils/Utils.h" namespace Application { bool test(HttpClient::Request &request, HttpClient::Response &response) { // Output incoming headers std::string s = R"( )"; for (auto const &pair : request.headers) { s += R"( )"; } // Output incoming url parameters s += R"( )"; for (auto const &pair : request.params) { s += R"( )"; } // Output incoming form data s += R"( )"; for (auto const &pair : request.data) { s += R"( )"; } // Output info about incoming files s += R"( )"; for (auto const &pair : request.files) { const std::string &field_name = pair.first; const Transfer::FileIncoming &file = pair.second; s += R"( )"; } s += R"(
Incoming headers
Header name Header value
)" + pair.first + R"( )" + pair.second + R"(
Incoming url parameters
Parameter name Parameter value
)" + pair.first + R"( )" + pair.second + R"(
Incoming form data
Form field Field value
)" + pair.first + R"( )" + pair.second + R"(
Incoming files
Form field Original name File type File size Uploaded name
)" + field_name + R"( )" + file.getName() + R"( )" + file.getType() + R"( )" + std::to_string(file.getSize() ) + R"( )" + file.getTmpName() + R"(
)"; std::unordered_map &headers = response.headers; // Set outgoing headers response.setStatusCode(Http::StatusCode::OK); headers["content-type"] = "text/html; charset=utf-8"; headers["accept-ranges"] = "bytes"; headers["content-length"] = std::to_string(s.size() ); headers["connection"] = "keep-alive"; headers["date"] = Utils::getDatetimeAsString(); // Additional headers // In additional headers may be placed values of cookies std::vector > additional; // additional.emplace_back("set-cookie", "key=value; expires=; path=/; domain=*"); // Send headers and data const std::chrono::milliseconds timeout(5000); if (response.sendHeaders(additional, timeout, s.empty() ) ) { if (false == s.empty() ) { response.sendData(s.data(), s.size(), timeout, true); } } return EXIT_SUCCESS; } };
X Tutup